Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augment error serializarion info #643

Merged

Conversation

nimakarimipour
Copy link
Contributor

This PR augments error information serialized by NullAway. At current state, if SerializeFixMetada is active, all reporting errors will be serialized to errors.tsv output file where each row has the format below:

MESSAGE_TYPE    MESSAGE   CLASS   METHOD

The above information does not contain any information regarding the element which involved in a pseudo-assignment of a @Nullable expression into a @NonNull. This information is crucial to detect origins of the error and other computable features.

With this PR, the format of the errors.tsv is changed to below to serialize all the required information to denote the involved element in the error:

message_type    message    enc_class    enc_method    kind    class   method     param    index    uri    

This PR involves other small refactoring (mostly renaming) as it was necessary to reuse the existing methods to produce the desired outputs.

Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me, though I think the testing infra has a couple bugs (see comments below).

One other thing I wonder is about the headers of the TSV. "class" and "method" are very generic, and they aren't the class or method where the error is happening, but the class and method referenced at the point the error is happening... maybe "target_class", "target_method", etc? Not sure if there is a better name than that, since it's sometimes the method being called and sometimes the method being overridden, etc. (cc: @msridhar )

@@ -50,16 +77,19 @@ public boolean equals(Object o) {
}
ErrorDisplay that = (ErrorDisplay) o;
return type.equals(that.type)
// To increase readability, a shorter version of the actual message might be present in the
// expected output of tests.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the notice, added it back
e9182db

}

@Override
public int hashCode() {
return Objects.hash(type, message, method, clazz);
return Objects.hash(type, message, encMethod, encClass);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this has a lot more fields, shouldn't those be part of its hashCode()? This was all fields before, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was all fields before, but according to the usage of these classes which are mostly used in test cases and are compared to at most 3/4 other instances, I did not see it necessary to include all fields. But you are right, it is better to be more precise about the hash.

04b3664

"test(java.lang.Object)",
"METHOD",
"com.uber.Super",
"test(java.lang.Object",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a missing ')' here? And shouldn't the test fail because of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it should fail, updated the test.

&& encMethod.equals(that.encMethod)
&& encClass.equals(that.encClass)
&& kind.equals(that.kind)
&& clazz.equals(that.clazz)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing comparing this.method, which I believe is why that test case with the missing parenthesis succeeds...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for noticing this, I just used the intellij generated code. updated it: 258a341

@@ -25,23 +25,23 @@
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.util.TreePath;
import com.uber.nullaway.ErrorMessage;
import com.uber.nullaway.fixserialization.location.FixLocation;
import com.uber.nullaway.fixserialization.location.SymbolLocation;
import java.util.Objects;

/** Stores information suggesting adding @Nullable on an element in source code. */
public class SuggestedNullableFixInfo {

/** FixLocation of the target element in source code. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is outdated given the renaming.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ddb2afa

Also ran git grep FixLocation, there is no usage of FixLocation anymore.

+ '\t'
+ "index"
+ '\t'
return "kind" + '\t' + "class" + '\t' + "method" + '\t' + "param" + '\t' + "index" + '\t'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this auto-formatted? I think it looks better in the previous/existing code (unless GJF recommends this style)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Java 1.8 there's String#join(CharSequence delimiter, CharSequence... elements), so another option would be:

String.join("\t", "kind", "class", "method", "param", "index", "uri")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. @nimakarimipour, probably a good idea to do this in all the places we are performing these tab-separated string concatenations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a8fdd11

@Stephan202 thank you for the suggestion :)
@lazaroclapp replaced all multiple calls with single join call.

@nimakarimipour
Copy link
Contributor Author

@lazaroclapp Resolved all comments and changed headers to use (target_kind, target_class, target_method).
ab046f9
This is ready for another review.

Regarding changing null\tnull\t... to \t\t..., that requires escaping to be picked by split as individual columns and at this moment I think it may be simpler to just go with null\tnull\t..., please let me know if you prefer the other approach and escaping. Thanks.

Copy link
Collaborator

@lazaroclapp lazaroclapp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 !

@nimakarimipour nimakarimipour merged commit 658f4c3 into uber:master Aug 26, 2022
@nimakarimipour nimakarimipour deleted the nimak/augment-error-serializarion branch August 26, 2022 22:10
nimakarimipour added a commit to ucr-riple/NullAwayAnnotator that referenced this pull request Sep 1, 2022
#### ~~This PR is Built upon GH-51~~ GH-51 is landed.

-----

This PR resolves #47 by updating `Error` instance creation according to the latest changes.

In the new release of NullAway (Specifically [PR643](uber/NullAway#643)), information of the non-null target (the element involved in the pseudo-assignment of a @nullable expression into a @nonnull and causing the error) is serialized along the reporting errors in the `errors.tsv`.

Header of `errors.tsv` files is changed from below:
```
MESSAGE_TYPE    MESSAGE   CLASS   METHOD
```
to:
```
message_type    message    enc_class    enc_method    target_kind    target_class   target_method     param    index    uri    
```

This requires updates on how `Error` instances are created due to change in `errors.tsv` files contents.

-----
~~Note: tests for `core` module are temporarily excluded in this PR for CI as they are only compatible with NullAway verion `0.9.10`.~~ _All_ tests are included since `NullAway 0.9.10` is released.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants