-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serialization of Type Change Suggestions for Type Violations. (#517)
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](https://github.com/nimakarimipour/NullAwayAutoFixer) 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```. ```java class Foo { Object bar = new Object(); void baz(){ this.bar = null; } } ``` This PR enables ```NullAway``` to suggest ```bar``` type to be ```@Nullable``` to resolve the error and creates two output files. ```errors.tsv``` where all reporting errors are stored and ```fixes.tsv``` where all the type change suggestions are stored. 1. ```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``` 2. ```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``` via ```ErrorProneFlags```: ``` "-XepOpt:NullAway:SerializeFixMetadata=true" "-XepOpt:NullAway:FixSerializationConfigPath=configpath" ``` When ```-XepOpt:NullAway:SerializeFixMetadata=true``` is observed in the flags, ```NullAway``` will look for a file at ```FixSerializationConfigPath``` to activate/deactivate serialization features. Below is the ```FixMetadataConfigPath``` format: ```xml <serialization> <suggest activation="true" enclosing="true"/> <output> "outputdir" </output> <annotation> <nullable>javax.annotation.Nullable</nullable> <nonnull>javax.annotation.Nonnull</nonnull> </annotation> </serialization> ``` If ```-XepOpt:NullAway:SerializeFixMetadata=true``` is observed, NullAway will serialize all reporting errors to ```errors.tsv``` regardless of flag values in ```FixSerializationConfig```. Finding enclosing method/class for suggested ```fixes``` is costly and not always required, they can be controlled using ```enclosing ``` 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.
- Loading branch information
1 parent
5b5ad0d
commit 9dbdd65
Showing
29 changed files
with
2,304 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.