-
Notifications
You must be signed in to change notification settings - Fork 295
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
Serialization of Type Change Suggestions for Type Violations. #517
Conversation
Hello @msridhar and @lazaroclapp, I ran the new version on my benchmarks to make sure everything is working and the tool crashed, I fixed the bug and added a test case: e86e2a3. It seems methods and constructs have different values for Lazaro, there are a lot of comments on this PR and the GitHub UI is not working really well, for your convenience I rewrote my responses to some of your comments, please find them below:
Also you asked why we need to have a control flag on fix serialization, since fix serialization comes with a cost on performance, and in our diagnose phase where we rebuild the project per fix, we do not need to know the list of new fixes at every single build unless we are performing a deep search. I believe this is ready for another review, sorry for the delay, I did not expect it to take this long :) |
Doing another pass over the PR right now, but went over the responses to comments first, and they generally look good to me. Regarding the three questions in the summary:
Fine to leave for later. Maybe worth a comment in the code noting the potential issue, but filenames with
Agreed!
Responded inline. But, basically
Makes sense to me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically ready. One issue with the output from tests that I would really want fixed and the rest are a couple nits and questions. Hopefully, this should be a much easier review to address than the last one :)
import com.uber.nullaway.fixserialization.location.FixLocation; | ||
import com.uber.nullaway.fixserialization.out.ErrorInfo; | ||
import com.uber.nullaway.fixserialization.out.SuggestedFixInfo; | ||
import com.uber.nullaway.fixserialization.SerializationHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, probably a different name, but love how much cleaner this is in terms of changes to core NullAway! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to SerializationService
, please let me know if you still think I should rename it to something else.
.map( | ||
element -> ASTHelpers.getSymbol(getTreesInstance(state).getTree(element))) | ||
.collect(Collectors.toList())) | ||
.build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I said this before, but ImmutableList
also has a collector, so no need to generate the intermediate mutable list and copy the elements. See my response comment to the original change here.
nullaway/src/main/java/com/uber/nullaway/fixserialization/XMLUtil.java
Outdated
Show resolved
Hide resolved
nullaway/src/main/java/com/uber/nullaway/fixserialization/XMLUtil.java
Outdated
Show resolved
Hide resolved
nullaway/src/test/java/com/uber/nullaway/tools/SerializationTestHelper.java
Outdated
Show resolved
Hide resolved
nullaway/src/test/java/com/uber/nullaway/tools/SerializationTestHelper.java
Outdated
Show resolved
Hide resolved
"-XepOpt:NullAway:SerializeFixMetadata=true", | ||
"-XepOpt:NullAway:FixSerializationConfigPath=" + configPath)) | ||
.addSourceLines( | ||
"com/uber/android/Super.java", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Super.java
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" return h;", | ||
" }", | ||
" Object test_param(@Nullable String o) {", | ||
" // BUG: Diagnostic contains: passing @Nullable", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Match indentation of the following line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"package com.uber;", | ||
"import java.util.ArrayList;", | ||
"public class Child extends Super<String>{", | ||
" public void newSideEffect(ArrayList<String> op) {", | ||
" // BUG: Diagnostic contains: passing @Nullable", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Match indentation of the following line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @lazaroclapp, thank you very much for your comments. This is ready for another review, with best regards. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Consider fixing the one typo below before landing, but otherwise this looks ready to me! 🎉 🚀
if (output.size() != 0) { | ||
errorMessage | ||
.append(output.size()) | ||
.append(" unexpected fix(s) suggestions were found:") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't need the (s)
, "fix suggestions" is already plural.
@msridhar and @lazaroclapp Thank you very much for your comments, this was super educating for me. |
Following GH-517 If `serializeFixMetadata` is active, `NullAway` will serialize suggested type changes (currently just adding `@Nullable`). In the `FixSerializationConfig` file we can set a custom annotation that `NullAway` will use in the output serializations. However, this process can be simplified by just asking `NullAway` to serialize type change locations with a default annotation name, any tool processing this output can use their own preferred annotation. After this PR the following entity will be removed from the config `.xml` file: ```xml <annotation> <nonnull> ... </nonnull> <nullable> ... </nullable> </annotation ``` And a sample out below: ``` Field bar of Foo, ASSIGN_FIELD_NULLABLE, @nullable ``` Will be changed to simply: ``` Field bar of Foo, ASSIGN_FIELD_NULLABLE, nullable ```
Overview
This PR enables
NullAway
to serialize information on code locations to resolve the reporting errors if they can be resolved via a type change. This information can be used by other tools such as AutoFixer to have an understanding of the source code, code points where violations occurred, and possible solutions. In the example below,NullAway
will report the error:assigning @Nullable null to @Nonnull bar
.This PR enables
NullAway
to suggestbar
type to be@Nullable
to resolve the error and creates two output files.errors.tsv
where all reporting errors are stored andfixes.tsv
where all the type change suggestions are stored.errors.tsv
: Every row represents a reporting error with the format:MESSAGE_TYPE, MESSAGE, ENCLOSING CLASS, ENCLOSING METHOD
For instance:
ASSIGN_FIELD_NULLABLE, assigning nullable null to field bar, Foo, baz
fixes.tsv
: Every row represents a type change suggestion with the format:LOCATION, MESSAGE_TYPE, ANNOT
For instance:
Field bar of Foo, ASSIGN_FIELD_NULLABLE, @Nullable
To activate the feature above the following flags must be passed to
NullAway
viaErrorProneFlags
:When
-XepOpt:NullAway:SerializeFixMetadata=true
is observed in the flags,NullAway
will look for a file atFixSerializationConfigPath
to activate/deactivate serialization features.Below is the
FixMetadataConfigPath
format:If
-XepOpt:NullAway:SerializeFixMetadata=true
is observed, NullAway will serialize all reporting errors toerrors.tsv
regardless of flag values inFixSerializationConfig
.Finding enclosing method/class for suggested
fixes
is costly and not always required, they can be controlled usingenclosing
attribute in the config file above. If any of the keys in the template config above is not found, the default value will be considered.Please note, at the places where explicit
@Nonnull
is observed,NullAway
will acknowledge that annotation and will not suggest any type change.Implementation
All implemented classes reside in the
fixserialization
package. The goal of this PR is to createSuggestedFixInfo
objects which are type change suggestions of elements in the source code. Each of these objects contains a singleLocation
instance and anAnnotation
.Location
instances target an element in the source code. Throughout this PR the only suggested annotation inSuggestedFixInfo
instances is@Nullable
.The creation of
SuggestedFixInfo
objects is implemented throughErrorBuilder
. ThecreateErrorDescription
signature is changed and now it accepts a fifth argument callednonNullTarget
. If this parameter isnon-null
, the error involved a pseudo-assignment of a@Nullable
expression into a@NonNull
target, and this parameter is theSymbol
for that target. WheneverErrorBuilder
is asked to create anErrorDescription
object, it also creates aSuggestedFixInfo
targeting the parameternonNullTarget
to be@Nullable
.