Skip to content

Commit e39856e

Browse files
authored
Update to Error Prone 2.39.0 (#1228)
1 parent 5b22fb4 commit e39856e

8 files changed

Lines changed: 22 additions & 26 deletions

File tree

.github/workflows/continuous-integration.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ jobs:
2525
epVersion: 2.31.0
2626
- os: macos-latest
2727
java: 17
28-
epVersion: 2.38.0
28+
epVersion: 2.39.0
2929
- os: windows-latest
3030
java: 17
31-
epVersion: 2.38.0
31+
epVersion: 2.39.0
3232
- os: ubuntu-latest
3333
java: 17
34-
epVersion: 2.38.0
34+
epVersion: 2.39.0
3535
fail-fast: false
3636
runs-on: ${{ matrix.os }}
3737
steps:
@@ -60,7 +60,7 @@ jobs:
6060
ORG_GRADLE_PROJECT_epApiVersion: ${{ matrix.epVersion }}
6161
run: ./gradlew codeCoverageReport
6262
continue-on-error: true
63-
if: runner.os == 'Linux' && matrix.java == '17' && matrix.epVersion == '2.38.0' && github.repository == 'uber/NullAway'
63+
if: runner.os == 'Linux' && matrix.java == '17' && matrix.epVersion == '2.39.0' && github.repository == 'uber/NullAway'
6464
- name: Upload coverage reports to Codecov
6565
uses: codecov/codecov-action@v4
6666
with:

gradle/dependencies.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import org.gradle.util.VersionNumber
1919
// The oldest version of Error Prone that we support running on
2020
def oldestErrorProneVersion = "2.14.0"
2121
// Latest released Error Prone version that we've tested with
22-
def latestErrorProneVersion = "2.38.0"
22+
def latestErrorProneVersion = "2.39.0"
2323
// Default to using latest tested Error Prone version
2424
def defaultErrorProneVersion = latestErrorProneVersion
2525
def errorProneVersionToCompileAgainst = defaultErrorProneVersion

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private Description.Builder removeCastToNonNullFix(
378378
// should be currently pointing at said call.
379379
Tree currTree = state.getPath().getLeaf();
380380
Preconditions.checkArgument(
381-
currTree.getKind() == Tree.Kind.METHOD_INVOCATION,
381+
currTree instanceof MethodInvocationTree,
382382
"Expected castToNonNull invocation expression, found:\n%s",
383383
currTree);
384384
MethodInvocationTree invTree = (MethodInvocationTree) currTree;

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@
2323
package com.uber.nullaway;
2424

2525
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
26-
import static com.sun.source.tree.Tree.Kind.EXPRESSION_STATEMENT;
2726
import static com.sun.source.tree.Tree.Kind.IDENTIFIER;
2827
import static com.sun.source.tree.Tree.Kind.OTHER;
29-
import static com.sun.source.tree.Tree.Kind.PARENTHESIZED;
30-
import static com.sun.source.tree.Tree.Kind.TYPE_CAST;
3128
import static com.uber.nullaway.ASTHelpersBackports.hasDirectAnnotationWithSimpleName;
3229
import static com.uber.nullaway.ASTHelpersBackports.isStatic;
3330
import static com.uber.nullaway.ErrorBuilder.errMsgForInitializer;
@@ -59,6 +56,7 @@
5956
import com.sun.source.tree.AnnotatedTypeTree;
6057
import com.sun.source.tree.AnnotationTree;
6158
import com.sun.source.tree.ArrayAccessTree;
59+
import com.sun.source.tree.AssertTree;
6260
import com.sun.source.tree.AssignmentTree;
6361
import com.sun.source.tree.BinaryTree;
6462
import com.sun.source.tree.BlockTree;
@@ -1197,8 +1195,7 @@ private Description checkForReadBeforeInit(ExpressionTree tree, VisitorState sta
11971195
// is this possible?
11981196
return Description.NO_MATCH;
11991197
}
1200-
if (!config.assertsEnabled()
1201-
&& enclosingBlockPath.getLeaf().getKind().equals(Tree.Kind.ASSERT)) {
1198+
if (!config.assertsEnabled() && enclosingBlockPath.getLeaf() instanceof AssertTree) {
12021199
return Description.NO_MATCH;
12031200
}
12041201
if (!relevantInitializerMethodOrBlock(enclosingBlockPath, state)) {
@@ -1375,7 +1372,7 @@ private ImmutableSet<Element> safeInitByCalleeBefore(
13751372
safeInitMethods.add(privMethodElem);
13761373
}
13771374
// Hack: Handling try{...}finally{...} statement, see getSafeInitMethods
1378-
if (curStmt.getKind().equals(Tree.Kind.TRY)) {
1375+
if (curStmt instanceof TryTree) {
13791376
TryTree tryTree = (TryTree) curStmt;
13801377
// ToDo: Should we check initialization inside tryTree.getResources ? What is the scope of
13811378
// that initialization?
@@ -2356,7 +2353,7 @@ private Set<Element> getSafeInitMethods(
23562353
// as "top level" for the purposes of finding initialization methods. Any exception happening
23572354
// there is also an
23582355
// exception of the full method.
2359-
if (stmt.getKind().equals(Tree.Kind.TRY)) {
2356+
if (stmt instanceof TryTree) {
23602357
TryTree tryTree = (TryTree) stmt;
23612358
if (tryTree.getCatches().size() == 0) {
23622359
if (tryTree.getBlock() != null) {
@@ -2405,7 +2402,7 @@ private Set<Element> getSafeInitMethods(
24052402
}
24062403
return false;
24072404
};
2408-
if (stmt.getKind().equals(EXPRESSION_STATEMENT)) {
2405+
if (stmt instanceof ExpressionStatementTree) {
24092406
ExpressionTree expression = ((ExpressionStatementTree) stmt).getExpression();
24102407
if (invokeMatcher.matches(expression, state)) {
24112408
return ASTHelpers.getSymbol(expression);
@@ -2415,7 +2412,7 @@ private Set<Element> getSafeInitMethods(
24152412
}
24162413

24172414
private boolean isThisCall(StatementTree statementTree, VisitorState state) {
2418-
if (statementTree.getKind().equals(EXPRESSION_STATEMENT)) {
2415+
if (statementTree instanceof ExpressionStatementTree) {
24192416
ExpressionTree expression = ((ExpressionStatementTree) statementTree).getExpression();
24202417
return Matchers.methodInvocation(THIS_MATCHER).matches(expression, state);
24212418
}
@@ -2754,7 +2751,7 @@ private Description matchDereference(
27542751
}
27552752

27562753
private static boolean isThisIdentifier(ExpressionTree expressionTree) {
2757-
return expressionTree.getKind().equals(IDENTIFIER)
2754+
return expressionTree instanceof IdentifierTree
27582755
&& ((IdentifierTree) expressionTree).getName().toString().equals("this");
27592756
}
27602757

@@ -2777,11 +2774,11 @@ private static ExpressionTree stripParensAndCasts(ExpressionTree expr) {
27772774
boolean someChange = true;
27782775
while (someChange) {
27792776
someChange = false;
2780-
if (expr.getKind().equals(PARENTHESIZED)) {
2777+
if (expr instanceof ParenthesizedTree) {
27812778
expr = ((ParenthesizedTree) expr).getExpression();
27822779
someChange = true;
27832780
}
2784-
if (expr.getKind().equals(TYPE_CAST)) {
2781+
if (expr instanceof TypeCastTree) {
27852782
expr = ((TypeCastTree) expr).getExpression();
27862783
someChange = true;
27872784
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ private static boolean isBoxingMethod(Symbol.MethodSymbol methodSymbol) {
455455
Tree tree = argumentNode.getTree();
456456
if (tree == null) {
457457
return null; // Not an AP
458-
} else if (tree.getKind().equals(Tree.Kind.METHOD_INVOCATION)) {
458+
} else if (tree instanceof MethodInvocationTree) {
459459
// Check for boxing call
460460
MethodInvocationTree methodInvocationTree = (MethodInvocationTree) tree;
461461
if (methodInvocationTree.getArguments().size() == 1

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import com.google.errorprone.VisitorState;
2626
import com.google.errorprone.util.ASTHelpers;
27-
import com.sun.source.tree.Tree;
27+
import com.sun.source.tree.MethodTree;
2828
import com.sun.source.util.TreePath;
2929
import com.sun.tools.javac.code.Symbol;
3030
import com.uber.nullaway.NullabilityUtil;
@@ -65,7 +65,7 @@ public void onNonNullFieldAssignment(
6565
// state parameter
6666
TreePath pathToMethod =
6767
NullabilityUtil.findEnclosingMethodOrLambdaOrInitializer(state.getPath());
68-
if (pathToMethod == null || pathToMethod.getLeaf().getKind() != Tree.Kind.METHOD) {
68+
if (pathToMethod == null || !(pathToMethod.getLeaf() instanceof MethodTree)) {
6969
return;
7070
}
7171
Symbol symbol = ASTHelpers.getSymbol(pathToMethod.getLeaf());

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.google.errorprone.VisitorState;
3535
import com.google.errorprone.util.ASTHelpers;
3636
import com.sun.source.tree.ExpressionTree;
37-
import com.sun.source.tree.Tree;
37+
import com.sun.source.tree.MethodInvocationTree;
3838
import com.sun.tools.javac.code.Symbol;
3939
import com.sun.tools.javac.code.Types;
4040
import com.sun.tools.javac.util.Context;
@@ -164,8 +164,7 @@ public boolean onOverrideMayBeNullExpr(
164164
if (isNullableFieldInLibraryModels(exprSymbol)) {
165165
return true;
166166
}
167-
if (!(expr.getKind() == Tree.Kind.METHOD_INVOCATION
168-
&& exprSymbol instanceof Symbol.MethodSymbol)) {
167+
if (!(expr instanceof MethodInvocationTree && exprSymbol instanceof Symbol.MethodSymbol)) {
169168
return exprMayBeNull;
170169
}
171170
OptimizedLibraryModels optLibraryModels = getOptLibraryModels(state.context);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.google.errorprone.util.ASTHelpers;
2828
import com.sun.source.tree.ClassTree;
2929
import com.sun.source.tree.ExpressionTree;
30-
import com.sun.source.tree.Tree;
30+
import com.sun.source.tree.MethodInvocationTree;
3131
import com.sun.source.util.TreePath;
3232
import com.sun.tools.javac.code.Symbol;
3333
import com.sun.tools.javac.code.Symtab;
@@ -89,7 +89,7 @@ public boolean onOverrideMayBeNullExpr(
8989
if (exprMayBeNull) {
9090
return true;
9191
}
92-
if (expr.getKind() == Tree.Kind.METHOD_INVOCATION
92+
if (expr instanceof MethodInvocationTree
9393
&& exprSymbol instanceof Symbol.MethodSymbol
9494
&& optionalIsGetCall((Symbol.MethodSymbol) exprSymbol, state.getTypes())) {
9595
return true;

0 commit comments

Comments
 (0)