Skip to content

Commit 1a74cd4

Browse files
authored
Revert "Model Lombok-generated equals methods as having a @nullable p… (#886)
…arameter (#874)" This reverts commit 5fbee1f. It turns out that this change requires a couple of other changes along with it, including #880 and better overall checking of overriding of `equals()` methods. We want to get a release out soon, so temporarily revert this change; we will restore it after cutting the release.
1 parent c44ab8d commit 1a74cd4

File tree

13 files changed

+34
-53
lines changed

13 files changed

+34
-53
lines changed

nullaway/src/main/java/com/uber/nullaway/NullAway.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,10 @@ private Description checkParamOverriding(
761761
// Check handlers for any further/overriding nullness information
762762
overriddenMethodArgNullnessMap =
763763
handler.onOverrideMethodInvocationParametersNullability(
764-
state, overriddenMethod, isOverriddenMethodAnnotated, overriddenMethodArgNullnessMap);
764+
state.context,
765+
overriddenMethod,
766+
isOverriddenMethodAnnotated,
767+
overriddenMethodArgNullnessMap);
765768

766769
// If we have an unbound method reference, the first parameter of the overridden method must be
767770
// @NonNull, as this parameter will be used as a method receiver inside the generated lambda.
@@ -1712,7 +1715,7 @@ private Description handleInvocation(
17121715
// Allow handlers to override the list of non-null argument positions
17131716
argumentPositionNullness =
17141717
handler.onOverrideMethodInvocationParametersNullability(
1715-
state, methodSymbol, isMethodAnnotated, argumentPositionNullness);
1718+
state.context, methodSymbol, isMethodAnnotated, argumentPositionNullness);
17161719

17171720
// now actually check the arguments
17181721
// NOTE: the case of an invocation on a possibly-null reference

nullaway/src/main/java/com/uber/nullaway/dataflow/AccessPathNullnessPropagation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private static Node unwrapAssignExpr(Node node) {
206206
public NullnessStore initialStore(
207207
UnderlyingAST underlyingAST, List<LocalVariableNode> parameters) {
208208
return nullnessStoreInitializer.getInitialStore(
209-
underlyingAST, parameters, handler, state, config);
209+
underlyingAST, parameters, handler, state.context, state.getTypes(), config);
210210
}
211211

212212
@Override

nullaway/src/main/java/com/uber/nullaway/dataflow/CoreNullnessStoreInitializer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static com.uber.nullaway.Nullness.NONNULL;
44
import static com.uber.nullaway.Nullness.NULLABLE;
55

6-
import com.google.errorprone.VisitorState;
76
import com.google.errorprone.util.ASTHelpers;
87
import com.sun.source.tree.ClassTree;
98
import com.sun.source.tree.LambdaExpressionTree;
@@ -31,9 +30,9 @@ public NullnessStore getInitialStore(
3130
UnderlyingAST underlyingAST,
3231
List<LocalVariableNode> parameters,
3332
Handler handler,
34-
VisitorState state,
33+
Context context,
34+
Types types,
3535
Config config) {
36-
Context context = state.context;
3736
if (underlyingAST.getKind().equals(UnderlyingAST.Kind.ARBITRARY_CODE)) {
3837
// not a method or a lambda; an initializer expression or block
3938
UnderlyingAST.CFGStatement ast = (UnderlyingAST.CFGStatement) underlyingAST;
@@ -45,7 +44,8 @@ public NullnessStore getInitialStore(
4544
(UnderlyingAST.CFGLambda) underlyingAST,
4645
parameters,
4746
handler,
48-
state,
47+
context,
48+
types,
4949
config,
5050
getCodeAnnotationInfo(context));
5151
} else {
@@ -77,20 +77,20 @@ private static NullnessStore lambdaInitialStore(
7777
UnderlyingAST.CFGLambda underlyingAST,
7878
List<LocalVariableNode> parameters,
7979
Handler handler,
80-
VisitorState state,
80+
Context context,
81+
Types types,
8182
Config config,
8283
CodeAnnotationInfo codeAnnotationInfo) {
8384
// include nullness info for locals from enclosing environment
8485
EnclosingEnvironmentNullness environmentNullness =
85-
EnclosingEnvironmentNullness.instance(state.context);
86+
EnclosingEnvironmentNullness.instance(context);
8687
NullnessStore environmentMapping =
8788
Objects.requireNonNull(
8889
environmentNullness.getEnvironmentMapping(underlyingAST.getLambdaTree()),
8990
"no environment stored for lambda");
9091
NullnessStore.Builder result = environmentMapping.toBuilder();
9192
LambdaExpressionTree code = underlyingAST.getLambdaTree();
9293
// need to check annotation for i'th parameter of functional interface declaration
93-
Types types = state.getTypes();
9494
Symbol.MethodSymbol fiMethodSymbol = NullabilityUtil.getFunctionalInterfaceMethod(code, types);
9595
com.sun.tools.javac.util.List<Symbol.VarSymbol> fiMethodParameters =
9696
fiMethodSymbol.getParameters();
@@ -119,7 +119,7 @@ private static NullnessStore lambdaInitialStore(
119119
}
120120
fiArgumentPositionNullness =
121121
handler.onOverrideMethodInvocationParametersNullability(
122-
state, fiMethodSymbol, isFIAnnotated, fiArgumentPositionNullness);
122+
context, fiMethodSymbol, isFIAnnotated, fiArgumentPositionNullness);
123123

124124
for (int i = 0; i < parameters.size(); i++) {
125125
LocalVariableNode param = parameters.get(i);

nullaway/src/main/java/com/uber/nullaway/dataflow/NullnessStoreInitializer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.uber.nullaway.dataflow;
22

3-
import com.google.errorprone.VisitorState;
43
import com.google.errorprone.util.ASTHelpers;
54
import com.sun.source.tree.ClassTree;
65
import com.sun.source.util.Trees;
76
import com.sun.tools.javac.code.Symbol;
7+
import com.sun.tools.javac.code.Types;
88
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
99
import com.sun.tools.javac.util.Context;
1010
import com.uber.nullaway.Config;
@@ -30,15 +30,17 @@ public abstract class NullnessStoreInitializer {
3030
* @param underlyingAST The AST node being matched.
3131
* @param parameters list of local variable nodes.
3232
* @param handler reference to the handler invoked.
33-
* @param state the visitor state.
33+
* @param context context.
34+
* @param types types.
3435
* @param config config for analysis.
3536
* @return Initial Nullness store.
3637
*/
3738
public abstract NullnessStore getInitialStore(
3839
UnderlyingAST underlyingAST,
3940
List<LocalVariableNode> parameters,
4041
Handler handler,
41-
VisitorState state,
42+
Context context,
43+
Types types,
4244
Config config);
4345

4446
/**

nullaway/src/main/java/com/uber/nullaway/handlers/BaseNoOpHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public boolean onOverrideFieldNullability(Symbol field) {
126126

127127
@Override
128128
public Nullness[] onOverrideMethodInvocationParametersNullability(
129-
VisitorState state,
129+
Context context,
130130
Symbol.MethodSymbol methodSymbol,
131131
boolean isAnnotated,
132132
Nullness[] argumentPositionNullness) {

nullaway/src/main/java/com/uber/nullaway/handlers/CompositeHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ public boolean onOverrideFieldNullability(Symbol field) {
149149

150150
@Override
151151
public Nullness[] onOverrideMethodInvocationParametersNullability(
152-
VisitorState state,
152+
Context context,
153153
Symbol.MethodSymbol methodSymbol,
154154
boolean isAnnotated,
155155
Nullness[] argumentPositionNullness) {
156156
for (Handler h : handlers) {
157157
argumentPositionNullness =
158158
h.onOverrideMethodInvocationParametersNullability(
159-
state, methodSymbol, isAnnotated, argumentPositionNullness);
159+
context, methodSymbol, isAnnotated, argumentPositionNullness);
160160
}
161161
return argumentPositionNullness;
162162
}

nullaway/src/main/java/com/uber/nullaway/handlers/Handler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Nullness onOverrideMethodReturnNullability(
192192
* considered isAnnotated or not. We use a mutable map for performance, but it should not outlive
193193
* the chain of handler invocations.
194194
*
195-
* @param state The current visitor state.
195+
* @param context The current context.
196196
* @param methodSymbol The method symbol for the method in question.
197197
* @param isAnnotated A boolean flag indicating whether the called method is considered to be
198198
* within isAnnotated or unannotated code, used to avoid querying for this information
@@ -205,7 +205,7 @@ Nullness onOverrideMethodReturnNullability(
205205
* handler.
206206
*/
207207
Nullness[] onOverrideMethodInvocationParametersNullability(
208-
VisitorState state,
208+
Context context,
209209
Symbol.MethodSymbol methodSymbol,
210210
boolean isAnnotated,
211211
Nullness[] argumentPositionNullness);

nullaway/src/main/java/com/uber/nullaway/handlers/InferredJARModelsHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.sun.source.tree.Tree;
2929
import com.sun.tools.javac.code.Symbol;
3030
import com.sun.tools.javac.code.Type;
31+
import com.sun.tools.javac.util.Context;
3132
import com.uber.nullaway.Config;
3233
import com.uber.nullaway.NullAway;
3334
import com.uber.nullaway.Nullness;
@@ -121,7 +122,7 @@ private void loadStubxFiles() {
121122

122123
@Override
123124
public Nullness[] onOverrideMethodInvocationParametersNullability(
124-
VisitorState state,
125+
Context context,
125126
Symbol.MethodSymbol methodSymbol,
126127
boolean isAnnotated,
127128
Nullness[] argumentPositionNullness) {

nullaway/src/main/java/com/uber/nullaway/handlers/LibraryModelsHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ public NullnessHint onDataflowVisitFieldAccess(
103103

104104
@Override
105105
public Nullness[] onOverrideMethodInvocationParametersNullability(
106-
VisitorState state,
106+
Context context,
107107
Symbol.MethodSymbol methodSymbol,
108108
boolean isAnnotated,
109109
Nullness[] argumentPositionNullness) {
110-
OptimizedLibraryModels optimizedLibraryModels = getOptLibraryModels(state.context);
110+
OptimizedLibraryModels optimizedLibraryModels = getOptLibraryModels(context);
111111
ImmutableSet<Integer> nullableParamsFromModel =
112112
optimizedLibraryModels.explicitlyNullableParameters(methodSymbol);
113113
ImmutableSet<Integer> nonNullParamsFromModel =

nullaway/src/main/java/com/uber/nullaway/handlers/LombokHandler.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,4 @@ public Nullness onOverrideMethodReturnNullability(
8686
}
8787
return returnNullness;
8888
}
89-
90-
/**
91-
* Mark the first argument of Lombok-generated {@code equals} methods as {@code @Nullable}, since
92-
* Lombok does not generate the annotation.
93-
*/
94-
@Override
95-
public Nullness[] onOverrideMethodInvocationParametersNullability(
96-
VisitorState state,
97-
Symbol.MethodSymbol methodSymbol,
98-
boolean isAnnotated,
99-
Nullness[] argumentPositionNullness) {
100-
if (ASTHelpers.hasAnnotation(methodSymbol, LOMBOK_GENERATED_ANNOTATION_NAME, state)) {
101-
// We assume that Lombok-generated equals methods with a single argument override
102-
// Object.equals and are not an overload.
103-
if (methodSymbol.getSimpleName().contentEquals("equals")
104-
&& methodSymbol.params().size() == 1) {
105-
// The parameter is not annotated with @Nullable, but it should be.
106-
argumentPositionNullness[0] = Nullness.NULLABLE;
107-
}
108-
}
109-
return argumentPositionNullness;
110-
}
11189
}

0 commit comments

Comments
 (0)