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

Serialization of Type Change Suggestions for Type Violations. #517

Merged
merged 388 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
388 commits
Select commit Hold shift + click to select a range
a55d27f
added updated config version
nimakarimipour Jun 20, 2021
a3a45e2
Merge branch 'master' of https://github.com/uber/NullAway into method…
nimakarimipour Jun 20, 2021
a63fe2a
updated to lastest upstream main
nimakarimipour Jun 20, 2021
572725a
updated config
nimakarimipour Jun 20, 2021
64c9daa
updated config
nimakarimipour Jun 20, 2021
8dbc0d7
update
nimakarimipour Jun 20, 2021
eeb94f3
changed structure
nimakarimipour Jun 20, 2021
b7e395a
update
nimakarimipour Jun 20, 2021
ba20acd
update
nimakarimipour Jun 20, 2021
d487942
update
nimakarimipour Jun 20, 2021
d8d320b
update
nimakarimipour Jun 20, 2021
53d3722
update
nimakarimipour Jun 22, 2021
79dcea5
update
nimakarimipour Jun 27, 2021
1a01457
update
nimakarimipour Jun 28, 2021
047ebdf
update
nimakarimipour Jun 29, 2021
c8875ab
update
nimakarimipour Jun 29, 2021
dac44ae
update
nimakarimipour Jun 30, 2021
b9343d2
update
nimakarimipour Jun 30, 2021
61b6b13
update
nimakarimipour Jun 30, 2021
0577229
update
nimakarimipour Jun 30, 2021
956d3c5
update
nimakarimipour Jun 30, 2021
337cf92
update
nimakarimipour Jun 30, 2021
2a15052
update
nimakarimipour Jun 30, 2021
53d4873
refactored
nimakarimipour Jul 1, 2021
1e949b6
refactored
nimakarimipour Jul 1, 2021
cf63081
update
nimakarimipour Jul 1, 2021
4c354a1
update
nimakarimipour Jul 8, 2021
f83e92d
update
nimakarimipour Jul 8, 2021
d8a9c72
update
nimakarimipour Jul 10, 2021
4136794
update
nimakarimipour Jul 13, 2021
0443772
update
nimakarimipour Jul 13, 2021
86e1780
update
nimakarimipour Jul 13, 2021
0f891e2
update
nimakarimipour Jul 13, 2021
2dc0618
update
nimakarimipour Jul 13, 2021
891532d
update
nimakarimipour Jul 14, 2021
fb63953
update
nimakarimipour Jul 15, 2021
e10fa96
update
nimakarimipour Jul 15, 2021
62455f0
update
nimakarimipour Jul 27, 2021
970af1b
update
nimakarimipour Jul 29, 2021
a0b23b2
update
nimakarimipour Jul 30, 2021
512465b
update
nimakarimipour Aug 2, 2021
155431a
update
nimakarimipour Aug 2, 2021
757ccb3
update
nimakarimipour Aug 3, 2021
6065b20
update
nimakarimipour Aug 5, 2021
962b037
update
nimakarimipour Aug 11, 2021
5eb78bf
update
nimakarimipour Aug 11, 2021
9fc19b5
update
nimakarimipour Aug 11, 2021
bc60d34
update
nimakarimipour Aug 20, 2021
3273675
update
nimakarimipour Aug 20, 2021
5e3c4c4
update
nimakarimipour Aug 20, 2021
3620624
update
nimakarimipour Aug 22, 2021
d72989e
update
nimakarimipour Aug 22, 2021
eca5598
update
nimakarimipour Aug 23, 2021
301f045
update
nimakarimipour Aug 29, 2021
f42ef3c
update
nimakarimipour Aug 31, 2021
4705617
update
nimakarimipour Aug 31, 2021
dbaa2f6
update
nimakarimipour Sep 1, 2021
06f0e8b
update
nimakarimipour Sep 1, 2021
8234a2b
update
nimakarimipour Sep 2, 2021
bd006b0
update
nimakarimipour Sep 9, 2021
3772d54
update
nimakarimipour Sep 9, 2021
406a85c
update
nimakarimipour Sep 9, 2021
adc6165
update
nimakarimipour Sep 10, 2021
4b4d455
update
nimakarimipour Sep 11, 2021
79d443f
update
nimakarimipour Sep 15, 2021
b39089a
update
nimakarimipour Sep 15, 2021
e4914aa
update
nimakarimipour Sep 21, 2021
6184f04
update
nimakarimipour Sep 21, 2021
24f340d
update
nimakarimipour Sep 21, 2021
36d1095
update
nimakarimipour Sep 25, 2021
de0b338
update
nimakarimipour Oct 4, 2021
f61c5c0
update
nimakarimipour Oct 19, 2021
9e18f70
update
nimakarimipour Oct 19, 2021
d9a957c
update
nimakarimipour Oct 19, 2021
7dacef4
update
nimakarimipour Oct 22, 2021
94334b9
update
nimakarimipour Nov 29, 2021
952a9ea
updated with upstream
nimakarimipour Nov 29, 2021
8f2079f
Prepare for release 0.9.2.7-LOCAL
nimakarimipour Dec 1, 2021
97bee30
Prepare for next development version.
nimakarimipour Dec 1, 2021
cde273c
begin
nimakarimipour Dec 9, 2021
99a22f0
make writer methods non-static.
nimakarimipour Dec 10, 2021
f824f25
made autofix path configurable
nimakarimipour Dec 10, 2021
305daf3
making path configurable
nimakarimipour Dec 13, 2021
efc3cb7
made description of error message visible
nimakarimipour Dec 14, 2021
e89d1ee
made description of error message visible
nimakarimipour Dec 14, 2021
2ca191b
removed a bug, always creating auotofixconfig
nimakarimipour Dec 14, 2021
3a957f4
removed a bug, always creating auotofixconfig
nimakarimipour Dec 14, 2021
78a30e9
removed a bug, integer overflow
nimakarimipour Dec 14, 2021
15f743d
Merge branch 'master' into autofix
nimakarimipour Dec 14, 2021
322d997
fixed error with ubuntu-8
nimakarimipour Dec 14, 2021
07be0be
changed infrastructure for testing to pass errorprone 2.10 CI, hopefu…
nimakarimipour Dec 14, 2021
501675e
removed redundant test
nimakarimipour Dec 14, 2021
27af317
minor refactoring
nimakarimipour Dec 14, 2021
96a2620
added json dependencies to dependencies.gradle
nimakarimipour Dec 14, 2021
5bf6df1
removed a white line
nimakarimipour Dec 15, 2021
cbd0c84
fixed the error with publishToMavenLocal signing
nimakarimipour Dec 15, 2021
2c90b12
removed default path
nimakarimipour Dec 15, 2021
707b6ad
removed compilationUnitTree from fix object
nimakarimipour Dec 15, 2021
1913a0f
minor toStrginModification
nimakarimipour Dec 15, 2021
fe8a3c7
refactored Location class
nimakarimipour Dec 15, 2021
60955eb
minimalized Location class
nimakarimipour Dec 15, 2021
b648799
minimalized Location class
nimakarimipour Dec 15, 2021
51fe625
converted strings to paths
nimakarimipour Dec 15, 2021
cd5bfcc
removed pckg and compulsory fields from fix
nimakarimipour Dec 15, 2021
0cd2450
implemnted fix suggestions via handlers
nimakarimipour Dec 15, 2021
71b75c4
removed fixer class
nimakarimipour Dec 15, 2021
8a4e8f7
resolved issues in previous PR
nimakarimipour Dec 16, 2021
2664ff2
minor changes: white line removal
nimakarimipour Dec 16, 2021
2db08ab
removed last trace of any hard code path
nimakarimipour Dec 16, 2021
15d93b0
super minor modification in error message text
nimakarimipour Dec 16, 2021
fadc5d8
trigger CI
nimakarimipour Dec 16, 2021
ed79959
removed hard code path for tests
nimakarimipour Dec 16, 2021
4d1fc0d
merge lastest changes of upstream:master
nimakarimipour Dec 24, 2021
cafa0ed
reverted changes in readme and changelog (mistake by idea)
nimakarimipour Dec 24, 2021
70bd7aa
removed whitespaces
nimakarimipour Dec 24, 2021
846255f
reverted mistakes by a name change
nimakarimipour Dec 24, 2021
38853f9
removed unrelated changes for this PR
nimakarimipour Dec 24, 2021
e168bf2
added partial documents and slight refactoring
nimakarimipour Dec 25, 2021
0bb7581
added partial documents
nimakarimipour Dec 25, 2021
e181f65
added documents and removed toStrings
nimakarimipour Dec 25, 2021
55f0a2d
added partial comments and slight refactor
nimakarimipour Dec 25, 2021
56e3a9a
Finalized comments
nimakarimipour Dec 25, 2021
4bd6e1e
slight refactor and comment addition
nimakarimipour Dec 25, 2021
871af2a
slight refactor and comment addition
nimakarimipour Dec 25, 2021
cb44027
Flag name change request completed.
nimakarimipour Dec 25, 2021
fcf8344
removed two unnecessary tests
nimakarimipour Dec 25, 2021
bd570e8
No fix when explicit @Nonnull annot exists.
nimakarimipour Dec 25, 2021
5b4c3c4
removed unused header in csv files
nimakarimipour Dec 27, 2021
52ec612
Changed exception message.
nimakarimipour Dec 28, 2021
c722852
Moved SeperatedValueDisplay interface to a different pkg.
nimakarimipour Dec 28, 2021
19fa64a
Changed DEEP name to ENCLOSING.
nimakarimipour Dec 28, 2021
37ef1b1
Merge branch 'master' of github.com:uber/NullAway into fix_suggest
nimakarimipour Dec 29, 2021
4eb83dd
Converted json to xml.
nimakarimipour Jan 1, 2022
c79c438
removed extra line
nimakarimipour Jan 1, 2022
bf68c2d
Removed extra white line.
nimakarimipour Jan 1, 2022
0af0ac7
Removed extra white line.
nimakarimipour Jan 1, 2022
5207bf5
Removed suggest handler.
nimakarimipour Jan 2, 2022
79c1f6c
Added javadoc.
nimakarimipour Jan 3, 2022
49e3b2d
Minor change in javadoc.
nimakarimipour Jan 3, 2022
411718d
Changed all years in headers to 2022.
nimakarimipour Jan 3, 2022
de094db
Renamed a variable.
nimakarimipour Jan 3, 2022
db12b59
Renamed Writer to Serializer and minor refactoring.
nimakarimipour Jan 3, 2022
b2411af
Renamed to serializer.xml.
nimakarimipour Jan 3, 2022
41833d9
Brought back DummyOptionsConfig constructor.
nimakarimipour Jan 4, 2022
f2c044f
Renamed fixable to nonNullTarget.
nimakarimipour Jan 4, 2022
3c22394
Renamed suggest to serializeFixSuggestion.
nimakarimipour Jan 4, 2022
732f7ad
Applied suggestion.
nimakarimipour Jan 4, 2022
3751dcf
Update nullaway/src/main/java/com/uber/nullaway/fixserialization/Loca…
nimakarimipour Jan 4, 2022
a8d32ab
Renamed to SeparatedValueDisplay.
nimakarimipour Jan 4, 2022
7771f12
Changed flag to accept config path rather tahn outputpath.
nimakarimipour Jan 4, 2022
c587e70
Removed duplicate files.
nimakarimipour Jan 4, 2022
7e9e267
Removed white line.
nimakarimipour Jan 4, 2022
523de30
Update nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java
nimakarimipour Jan 6, 2022
fa36d6c
Renamed argument to nonNull.
nimakarimipour Jan 6, 2022
7bad2b3
Clarified a javadoc comment.
nimakarimipour Jan 6, 2022
d145541
Renamed to FixLocation.
nimakarimipour Jan 6, 2022
d70c817
Made method return Nonnull and thr exception instead.
nimakarimipour Jan 6, 2022
5e2b989
Removed blank line.
nimakarimipour Jan 7, 2022
9960615
Removed log error flag and renamed classes.
nimakarimipour Jan 7, 2022
4ceb827
Capitilized flag.
nimakarimipour Jan 7, 2022
9111438
Removed unnecessary null check.
nimakarimipour Jan 7, 2022
a9746be
Applied suggestion.
nimakarimipour Jan 7, 2022
213108e
Removed flag from serialization config argument.
nimakarimipour Jan 7, 2022
c7b3d55
Renamed argument.
nimakarimipour Jan 7, 2022
79d59c5
Uopdated javadoc.
nimakarimipour Jan 7, 2022
04a65bd
Removed null check.
nimakarimipour Jan 7, 2022
0865072
Renamed to FixSerializationConfig.
nimakarimipour Jan 8, 2022
b68ac14
Made kind final.
nimakarimipour Jan 8, 2022
031bae1
Renamed to toStringWithDelimiter.
nimakarimipour Jan 8, 2022
0c3f775
Converted to tsv and remoned interface.
nimakarimipour Jan 10, 2022
ed8ee93
Merge branch 'master' into fix_suggest
nimakarimipour Jan 10, 2022
a05aa6a
Applied try-with-resrouce.
nimakarimipour Jan 10, 2022
8ec01ad
Merge branch 'fix_suggest' of github.com:nimakarimipour/NullAway into…
nimakarimipour Jan 10, 2022
1330dc9
Renamed to AnnotationConfig.
nimakarimipour Jan 10, 2022
20f6218
Renamed reset and resetFile methods.
nimakarimipour Jan 10, 2022
458947f
Added documentation.
nimakarimipour Jan 10, 2022
bec0b95
Refactoring of FixLocation.
nimakarimipour Jan 10, 2022
288dfdd
Updated javadoc.
nimakarimipour Jan 10, 2022
e215939
Restored extra line.
nimakarimipour Jan 10, 2022
fc0f692
Refactored Location class.
nimakarimipour Jan 10, 2022
1fb38f3
Applied rename suggestions.
nimakarimipour Jan 10, 2022
56e22d3
Changhed to try-with-resource and added comment.
nimakarimipour Jan 10, 2022
f9b2276
Fix bug.
nimakarimipour Jan 10, 2022
c7398ca
Made EnclosingClassAndMethod field instance.
nimakarimipour Jan 10, 2022
48b092d
Merge branch 'master' into fix_suggest
nimakarimipour Jan 11, 2022
6088d2c
Update nullaway/src/main/java/com/uber/nullaway/fixserialization/out/…
nimakarimipour Jan 11, 2022
14c1a4f
Changed protected to private.
nimakarimipour Jan 11, 2022
966d4fd
Merge branch 'fix_suggest' of github.com:nimakarimipour/NullAway into…
nimakarimipour Jan 11, 2022
21f5ea8
Merge branch 'master' into fix_suggest
nimakarimipour Jan 13, 2022
cec2fa5
Merge branch 'master' of github.com:uber/NullAway into fix_suggest
nimakarimipour Jan 24, 2022
a8010cf
Inherited base class and resolved all missingBraces.
nimakarimipour Jan 24, 2022
9b0bbef
Merge branch 'fix_suggest' of github.com:nimakarimipour/NullAway into…
nimakarimipour Jan 24, 2022
8f602d0
Renamed home to tempRoot.
nimakarimipour Jan 24, 2022
e24a8f6
Renamed to writeAsXML
nimakarimipour Jan 24, 2022
9906b53
Renamed to addExpectedFixes
nimakarimipour Jan 24, 2022
8e93d0b
Improved error message.
nimakarimipour Jan 24, 2022
cff3428
Removed unneccessary try catch
nimakarimipour Jan 24, 2022
7d223c8
Changed error description.
nimakarimipour Jan 24, 2022
f0c9470
Added header validation to tests.
nimakarimipour Jan 24, 2022
e2ee6b3
Added a comment.
nimakarimipour Jan 24, 2022
7117c41
Converted list to array.
nimakarimipour Jan 25, 2022
3c865bc
Updated fail message.
nimakarimipour Jan 25, 2022
3a267d1
Changed from addToX to setX.
nimakarimipour Jan 25, 2022
222f6e6
Removed Arrays.deepToString
nimakarimipour Jan 25, 2022
91f19cd
Added a check.
nimakarimipour Jan 25, 2022
ca4987d
Renamed to Test.java
nimakarimipour Jan 25, 2022
cc23c7f
Made test stronger.
nimakarimipour Jan 25, 2022
77aecc2
Renamed to Test.java
nimakarimipour Jan 25, 2022
b909c3e
Modified Test.
nimakarimipour Jan 25, 2022
cb06464
Modified Test.
nimakarimipour Jan 25, 2022
15dbd13
Modified documentation.
nimakarimipour Jan 25, 2022
0c161cf
Modified documentation.
nimakarimipour Jan 25, 2022
71d2fa8
Added a precondition
nimakarimipour Jan 25, 2022
98f09db
Merged two if's and minor refactoring.
nimakarimipour Jan 25, 2022
750ff31
Added Getter.
nimakarimipour Jan 25, 2022
255bc60
Converted to Preconditions.checkNotNull.
nimakarimipour Jan 25, 2022
0c89e5e
Converted to ImmutableList.
nimakarimipour Jan 25, 2022
f4f1a84
Created a facade class for Fix Serialization Package.
nimakarimipour Jan 25, 2022
926e1b8
Removed unnecessary conversion.
nimakarimipour Jan 25, 2022
a68290d
Update javadoc
nimakarimipour Jan 25, 2022
cb7a92c
Update javadoc
nimakarimipour Jan 25, 2022
b60540c
Update javadoc
nimakarimipour Jan 26, 2022
c8b7d2d
Refined exception causes
nimakarimipour Jan 26, 2022
cf3d6d9
Catched illegal state
nimakarimipour Jan 26, 2022
63f31a3
Added getter
nimakarimipour Jan 27, 2022
f509702
Passed exception as cause argument.
nimakarimipour Jan 27, 2022
c0c5c81
Converted to toString()
nimakarimipour Jan 27, 2022
415a7df
Fixed exception cause.
nimakarimipour Jan 27, 2022
76eb3ab
Added xpath API
nimakarimipour Jan 27, 2022
8ae1004
Changed to private
nimakarimipour Jan 27, 2022
3c1e8dc
Added to cause arguments
nimakarimipour Jan 27, 2022
f7bf102
Added to cause arguments
nimakarimipour Jan 27, 2022
5997ae3
Added to cause arguments
nimakarimipour Jan 27, 2022
9dfa553
Chgangd to private
nimakarimipour Jan 27, 2022
e398a94
Moved to static method in interface
nimakarimipour Jan 27, 2022
275c31e
Moved to static method in interface
nimakarimipour Jan 27, 2022
7271a3e
Changd from public to private
nimakarimipour Jan 27, 2022
89b2f5d
Changd Name to Cursor
nimakarimipour Jan 27, 2022
99061e7
removed explicit toString()
nimakarimipour Jan 27, 2022
e86e2a3
Fixed a critical bug.
nimakarimipour Jan 27, 2022
3e8071c
Removed unnecessary replaceAll
nimakarimipour Jan 27, 2022
e649145
Renamd flag variable
nimakarimipour Jan 28, 2022
f69c5cf
Merge branch 'master' of https://github.com/uber/NullAway into fix_su…
nimakarimipour Feb 8, 2022
ccb5dfc
Merged with upstream and minor javadoc fixes
nimakarimipour Feb 8, 2022
5ef177a
Fixed error message
nimakarimipour Feb 8, 2022
798b7aa
Updated javadoc
nimakarimipour Feb 8, 2022
168b88a
Fixed exception stack frame
nimakarimipour Feb 8, 2022
b144824
Resolved test codes comments
nimakarimipour Feb 8, 2022
9499ce3
Renamed to SerializationService
nimakarimipour Feb 8, 2022
0602a68
Fixed comments plural
nimakarimipour Feb 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions nullaway/src/main/java/com/uber/nullaway/AbstractConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.errorprone.util.ASTHelpers;
import com.sun.tools.javac.code.Symbol;
import com.uber.nullaway.fixserialization.FixSerializationConfig;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -115,6 +117,27 @@ public abstract class AbstractConfig implements Config {

protected Set<String> customNullableAnnotations;

/**
* If active, NullAway will write all reporting errors in output directory. The output directory
* along with the activation status of other serialization features are stored in {@link
* FixSerializationConfig}.
*/
protected boolean serializationActivationFlag;

protected FixSerializationConfig fixSerializationConfig;

@Override
public boolean serializationIsActive() {
return serializationActivationFlag;
}

@Override
public FixSerializationConfig getSerializationConfig() {
Preconditions.checkArgument(
serializationActivationFlag, "Fix Serialization is not active, cannot access it's config.");
return fixSerializationConfig;
}

protected static Pattern getPackagePattern(Set<String> packagePrefixes) {
// noinspection ConstantConditions
String choiceRegexp =
Expand Down
18 changes: 18 additions & 0 deletions nullaway/src/main/java/com/uber/nullaway/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,30 @@

import com.google.common.collect.ImmutableSet;
import com.sun.tools.javac.code.Symbol;
import com.uber.nullaway.fixserialization.FixSerializationConfig;
import java.util.Set;
import javax.annotation.Nullable;

/** Provides configuration parameters for the nullability checker. */
public interface Config {

/**
* Checks if Serialization feature is active.
*
* @return true, if Fix Serialization feature is active.
*/
boolean serializationIsActive();

/**
* Getter method for {@link FixSerializationConfig}.
*
* <p>Fix Serialization feature must be activated, otherwise calling this method will fail the
* execution.
*
* @return {@link FixSerializationConfig} instance in Config.
*/
FixSerializationConfig getSerializationConfig();

/**
* Checks if a symbol comes from an annotated package.
*
Expand Down
11 changes: 11 additions & 0 deletions nullaway/src/main/java/com/uber/nullaway/DummyOptionsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.google.common.collect.ImmutableSet;
import com.sun.tools.javac.code.Symbol;
import com.uber.nullaway.fixserialization.FixSerializationConfig;
import java.util.Set;
import javax.annotation.Nullable;

Expand All @@ -53,6 +54,16 @@ public class DummyOptionsConfig implements Config {

public DummyOptionsConfig() {}
msridhar marked this conversation as resolved.
Show resolved Hide resolved

@Override
public boolean serializationIsActive() {
throw new IllegalStateException(ERROR_MESSAGE);
}

@Override
public FixSerializationConfig getSerializationConfig() {
throw new IllegalStateException(ERROR_MESSAGE);
}

@Override
public boolean fromAnnotatedPackage(Symbol.ClassSymbol symbol) {
throw new IllegalStateException(ERROR_MESSAGE);
Expand Down
69 changes: 58 additions & 11 deletions nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static com.uber.nullaway.NullAway.getTreesInstance;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand All @@ -51,6 +52,7 @@
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.DiagnosticSource;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.uber.nullaway.fixserialization.SerializationService;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -82,12 +84,18 @@ public class ErrorBuilder {
* @param errorMessage the error message object.
* @param descriptionBuilder the description builder for the error.
* @param state the visitor state (used for e.g. suppression finding).
* @param nonNullTarget if non-null, this error involved a pseudo-assignment of a @Nullable
msridhar marked this conversation as resolved.
Show resolved Hide resolved
* expression into a @NonNull target, and this parameter is the Symbol for that target.
* @return the error description
*/
Description createErrorDescription(
ErrorMessage errorMessage, Description.Builder descriptionBuilder, VisitorState state) {
ErrorMessage errorMessage,
Description.Builder descriptionBuilder,
VisitorState state,
@Nullable Symbol nonNullTarget) {
Tree enclosingSuppressTree = suppressibleNode(state.getPath());
return createErrorDescription(errorMessage, enclosingSuppressTree, descriptionBuilder, state);
return createErrorDescription(
errorMessage, enclosingSuppressTree, descriptionBuilder, state, nonNullTarget);
}

/**
Expand All @@ -97,13 +105,16 @@ Description createErrorDescription(
* @param suggestTree the location at which a fix suggestion should be made
* @param descriptionBuilder the description builder for the error.
* @param state the visitor state (used for e.g. suppression finding).
* @param nonNullTarget if non-null, this error involved a pseudo-assignment of a @Nullable
* expression into a @NonNull target, and this parameter is the Symbol for that target.
* @return the error description
*/
public Description createErrorDescription(
ErrorMessage errorMessage,
@Nullable Tree suggestTree,
Description.Builder descriptionBuilder,
VisitorState state) {
VisitorState state,
@Nullable Symbol nonNullTarget) {
Description.Builder builder = descriptionBuilder.setMessage(errorMessage.message);
String checkName = CORE_CHECK_NAME;
if (errorMessage.messageType.equals(GET_ON_EMPTY_OPTIONAL)) {
Expand All @@ -123,6 +134,14 @@ public Description createErrorDescription(
if (config.suggestSuppressions() && suggestTree != null) {
builder = addSuggestedSuppression(errorMessage, suggestTree, builder);
}

if (config.serializationIsActive()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we merge these two ifs and nest the nonNullTarget != null check? Just to separate out the full logic about serialization. Probably also worth a brief comment about which config flag this whole process is guarded by.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

98f09db

Merged and some more refactoring, looks a lot more clear now.

if (nonNullTarget != null) {
SerializationService.serializeFixSuggestion(config, state, nonNullTarget, errorMessage);
}
SerializationService.serializeReportingError(config, state, errorMessage);
}

// #letbuildersbuild
return builder.build();
}
Expand Down Expand Up @@ -201,19 +220,26 @@ private Description.Builder addSuggestedSuppression(
* @param descriptionBuilder the description builder for the error.
* @param state the visitor state for the location which triggered the error (i.e. for suppression
* finding)
* @param nonNullTarget if non-null, this error involved a pseudo-assignment of a @Nullable
* expression into a @NonNull target, and this parameter is the Symbol for that target.
* @return the error description.
*/
Description createErrorDescriptionForNullAssignment(
ErrorMessage errorMessage,
@Nullable Tree suggestTreeIfCastToNonNull,
Description.Builder descriptionBuilder,
VisitorState state) {
VisitorState state,
Symbol nonNullTarget) {
if (config.getCastToNonNullMethod() != null) {
return createErrorDescription(
errorMessage, suggestTreeIfCastToNonNull, descriptionBuilder, state);
errorMessage, suggestTreeIfCastToNonNull, descriptionBuilder, state, nonNullTarget);
} else {
return createErrorDescription(
errorMessage, suppressibleNode(state.getPath()), descriptionBuilder, state);
errorMessage,
suppressibleNode(state.getPath()),
descriptionBuilder,
state,
nonNullTarget);
}
}

Expand Down Expand Up @@ -311,21 +337,40 @@ private Description.Builder removeCastToNonNullFix(
return builder.addFix(fix);
}

/**
* Reports initialization errors where a constructor fails to guarantee non-fields are initialized
* along all paths at exit points.
*
* @param methodSymbol Constructor symbol.
* @param message Error message.
* @param state The VisitorState object.
* @param descriptionBuilder the description builder for the error.
* @param nonNullFields list of @Nonnull fields that are not guaranteed to be initialized along
* all paths at exit points of the constructor.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

void reportInitializerError(
Symbol.MethodSymbol methodSymbol,
String message,
VisitorState state,
Description.Builder descriptionBuilder) {
Description.Builder descriptionBuilder,
ImmutableList<Symbol> nonNullFields) {
// Check needed here, despite check in hasPathSuppression because initialization
// checking happens at the class-level (meaning state.getPath() might not include the
// method itself).
if (symbolHasSuppressWarningsAnnotation(methodSymbol, INITIALIZATION_CHECK_NAME)) {
return;
}
Tree methodTree = getTreesInstance(state).getTree(methodSymbol);
ErrorMessage errorMessage = new ErrorMessage(METHOD_NO_INIT, message);
state.reportMatch(
createErrorDescription(
new ErrorMessage(METHOD_NO_INIT, message), methodTree, descriptionBuilder, state));
createErrorDescription(errorMessage, methodTree, descriptionBuilder, state, null));
if (config.serializationIsActive()) {
// For now, we serialize each fix suggestion separately and measure their effectiveness
// separately
nonNullFields.forEach(
symbol ->
SerializationService.serializeFixSuggestion(config, state, symbol, errorMessage));
}
}

boolean symbolHasSuppressWarningsAnnotation(Symbol symbol, String suppression) {
Expand Down Expand Up @@ -429,14 +474,16 @@ void reportInitErrorOnField(Symbol symbol, VisitorState state, Description.Build
FIELD_NO_INIT, "@NonNull static field " + fieldName + " not initialized"),
tree,
builder,
state));
state,
symbol));
} else {
state.reportMatch(
createErrorDescription(
new ErrorMessage(FIELD_NO_INIT, "@NonNull field " + fieldName + " not initialized"),
tree,
builder,
state));
state,
symbol));
}
}
}
8 changes: 8 additions & 0 deletions nullaway/src/main/java/com/uber/nullaway/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ public enum MessageTypes {
WRONG_OVERRIDE_POSTCONDITION,
WRONG_OVERRIDE_PRECONDITION,
}

public String getMessage() {
return message;
}

public MessageTypes getMessageType() {
return messageType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.google.common.collect.ImmutableSet;
import com.google.errorprone.ErrorProneFlags;
import com.uber.nullaway.fixserialization.FixSerializationConfig;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Optional;
Expand Down Expand Up @@ -74,6 +75,11 @@ final class ErrorProneCLIFlagsConfig extends AbstractConfig {
static final String FL_JI_REGEX_MODEL_PATH = EP_FL_NAMESPACE + ":JarInferRegexStripModelJar";
static final String FL_JI_REGEX_CODE_PATH = EP_FL_NAMESPACE + ":JarInferRegexStripCodeJar";
static final String FL_ERROR_URL = EP_FL_NAMESPACE + ":ErrorURL";
/** --- Serialization configs --- */
static final String FL_FIX_SERIALIZATION = EP_FL_NAMESPACE + ":SerializeFixMetadata";

static final String FL_FIX_SERIALIZATION_CONFIG_PATH =
EP_FL_NAMESPACE + ":FixSerializationConfigPath";

private static final String DELIMITER = ",";

Expand Down Expand Up @@ -200,6 +206,35 @@ final class ErrorProneCLIFlagsConfig extends AbstractConfig {
+ FL_ACKNOWLEDGE_RESTRICTIVE
+ " is also set");
}
serializationActivationFlag = flags.getBoolean(FL_FIX_SERIALIZATION).orElse(false);
Optional<String> fixSerializationConfigPath = flags.get(FL_FIX_SERIALIZATION_CONFIG_PATH);
if (serializationActivationFlag && !fixSerializationConfigPath.isPresent()) {
throw new IllegalStateException(
"DO NOT report an issue to Error Prone for this crash! NullAway Fix Serialization configuration is "
+ "incorrect. "
+ "Must specify AutoFixer Output Directory, using the "
+ "-XepOpt:"
+ FL_FIX_SERIALIZATION_CONFIG_PATH
+ " flag. If you feel you have gotten this message in error report an issue"
+ " at https://github.com/uber/NullAway/issues.");
}
/*
* if fixSerializationActivationFlag is false, the default constructor is invoked for
* creating FixSerializationConfig which all features are deactivated. This lets the
* field be @Nonnull, allowing us to avoid null checks in various places.
*/
fixSerializationConfig =
msridhar marked this conversation as resolved.
Show resolved Hide resolved
serializationActivationFlag
? new FixSerializationConfig(fixSerializationConfigPath.get())
: new FixSerializationConfig();
if (serializationActivationFlag && isSuggestSuppressions) {
throw new IllegalStateException(
"In order to activate Fix Serialization mode ("
+ FL_FIX_SERIALIZATION
+ "), Suggest Suppressions mode must be deactivated ("
+ FL_SUGGEST_SUPPRESSIONS
+ ")");
}
}

private static ImmutableSet<String> getFlagStringSet(ErrorProneFlags flags, String flagName) {
Expand Down