Skip to content

Commit bfdd5cc

Browse files
authored
Update minimum supported Error Prone version to 2.25.0 (#1421)
This is a pre-cursor to #1396. Here we bump our minimum supported EP version to 2.25.0. This lets us clean up / remove a bunch of compatibility code. Also clean up some related dependencies. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated minimum Error Prone version requirement to 2.25.0 * Added a centralized Guava version (33.5.0-jre) and switched tests to use it * **Refactor** * Removed custom compatibility/backport layer and now use Error Prone's standard utilities directly * Simplified internals to rely on standard symbol helpers * **Tests** * Adjusted test configuration (annotated-package settings and test dependencies) for compatibility with the newer toolchain <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 913d98b commit bfdd5cc

File tree

13 files changed

+22
-107
lines changed

13 files changed

+22
-107
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ NullAway is *fast*. It is built as a plugin to [Error Prone](http://errorprone.
88

99
### Overview
1010

11-
NullAway requires that you build your code with [Error Prone](http://errorprone.info), version 2.14.0 or higher. See the [Error Prone documentation](http://errorprone.info/docs/installation) for instructions on getting started with Error Prone and integration with your build system. The instructions below assume you are using Gradle; see [the docs](https://github.com/uber/NullAway/wiki/Configuration#other-build-systems) for discussion of other build systems. If you are building with JSpecify mode enabled, we recommend building with the most recent JDK available; see [the wiki docs on JSpecify support](https://github.com/uber/NullAway/wiki/JSpecify-Support) for more details.
11+
NullAway requires that you build your code with [Error Prone](http://errorprone.info), version 2.25.0 or higher. See the [Error Prone documentation](http://errorprone.info/docs/installation) for instructions on getting started with Error Prone and integration with your build system. The instructions below assume you are using Gradle; see [the docs](https://github.com/uber/NullAway/wiki/Configuration#other-build-systems) for discussion of other build systems. If you are building with JSpecify mode enabled, we recommend building with the most recent JDK available; see [the wiki docs on JSpecify support](https://github.com/uber/NullAway/wiki/JSpecify-Support) for more details.
1212

1313
### Gradle
1414

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ shellcheck = "1.5.0"
1818

1919
errorProne = "2.45.0"
2020
errorProneJdk17 = "2.42.0"
21-
errorProneOldest = "2.14.0"
21+
errorProneOldest = "2.25.0"
2222

2323
semver4j = "3.1.0"
2424
jakarta-inject = "2.0.0"
2525
javax-inject = "1"
2626
gson = "2.13.1"
2727
guava = "31.1-jre"
28+
guava-latest = "33.5.0-jre"
2829
javax-validation = "2.0.1.Final"
2930
jspecify = "1.0.0"
3031
commons-io = "2.11.0"
@@ -78,6 +79,7 @@ error-prone-test-helpers = { module = "com.google.errorprone:error_prone_test_he
7879
checker-dataflow = { module = "org.checkerframework:dataflow-nullaway", version.ref = "check-framework" }
7980
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
8081
guava = { module = "com.google.guava:guava", version.ref = "guava" }
82+
guava-latest = { module = "com.google.guava:guava", version.ref = "guava-latest" }
8183
javax-validation = { module = "javax.validation:validation-api", version.ref = "javax-validation" }
8284
jspecify = { module = "org.jspecify:jspecify", version.ref = "jspecify" }
8385
commons-io = { module = "commons-io:commons-io", version.ref = "commons-io" }

guava-recent-unit-tests/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ dependencies {
3333
exclude group: "junit", module: "junit"
3434
}
3535
testImplementation libs.jsr305
36-
testImplementation "com.google.guava:guava:33.4.8-jre"
36+
testImplementation libs.guava.latest
3737

3838
errorProneOldest "com.google.errorprone:error_prone_check_api:${oldestErrorProneVersion}"
3939
errorProneOldest("com.google.errorprone:error_prone_test_helpers:${oldestErrorProneVersion}") {
4040
exclude group: "junit", module: "junit"
4141
}
42-
errorProneOldest libs.guava
42+
errorProneOldest libs.guava.latest
43+
44+
errorProneJdk17 libs.guava.latest
4345
}
4446

4547
// Create a task to test with the oldest supported version of Error Prone

guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,7 @@ public void setup() {
4747
Arrays.asList(
4848
"-d",
4949
temporaryFolder.getRoot().getAbsolutePath(),
50-
// Since Guava is now @NullMarked we shouldn't need com.google.common in the
51-
// annotated packages list.
52-
// We still need it here since we are still trying to support
53-
// Error Prone 2.14.0, on which reading @NullMarked from the package-info.java
54-
// file isn't working using ASTHelpers for some reason.
55-
// TODO Once we bump our minimum Error Prone version, remove com.google.common
56-
// from this list.
57-
"-XepOpt:NullAway:AnnotatedPackages=com.uber,com.google.common",
50+
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
5851
"-XepOpt:NullAway:UnannotatedSubPackages=com.uber.nullaway.[a-zA-Z0-9.]+.unannotated"));
5952
jspecifyCompilationHelper =
6053
CompilationTestHelper.newInstance(NullAway.class, getClass())

nullaway/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ dependencies {
8585

8686
// without this, some other version of the JetBrains annotations gets pulled in via transitive dependencies
8787
errorProneJdk17 libs.jetbrains.annotations
88+
errorProneOldest libs.jetbrains.annotations
8889
}
8990

9091
javadoc {

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

Lines changed: 0 additions & 57 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
package com.uber.nullaway;
2424

2525
import static com.google.errorprone.util.ASTHelpers.enclosingClass;
26-
import static com.uber.nullaway.ASTHelpersBackports.hasDirectAnnotationWithSimpleName;
26+
import static com.google.errorprone.util.ASTHelpers.hasDirectAnnotationWithSimpleName;
2727
import static com.uber.nullaway.NullabilityUtil.castToNonNull;
2828

2929
import com.google.common.base.Preconditions;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
package com.uber.nullaway;
2424

25-
import static com.uber.nullaway.ASTHelpersBackports.hasDirectAnnotationWithSimpleName;
26-
import static com.uber.nullaway.ASTHelpersBackports.isStatic;
25+
import static com.google.errorprone.util.ASTHelpers.hasDirectAnnotationWithSimpleName;
26+
import static com.google.errorprone.util.ASTHelpers.isStatic;
2727
import static com.uber.nullaway.ErrorMessage.MessageTypes.FIELD_NO_INIT;
2828
import static com.uber.nullaway.ErrorMessage.MessageTypes.GET_ON_EMPTY_OPTIONAL;
2929
import static com.uber.nullaway.ErrorMessage.MessageTypes.METHOD_NO_INIT;

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

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

2525
import static com.google.errorprone.BugPattern.SeverityLevel.WARNING;
26-
import static com.uber.nullaway.ASTHelpersBackports.hasDirectAnnotationWithSimpleName;
27-
import static com.uber.nullaway.ASTHelpersBackports.isStatic;
26+
import static com.google.errorprone.util.ASTHelpers.hasDirectAnnotationWithSimpleName;
27+
import static com.google.errorprone.util.ASTHelpers.isStatic;
2828
import static com.uber.nullaway.ErrorBuilder.errMsgForInitializer;
2929
import static com.uber.nullaway.NullabilityUtil.castToNonNull;
3030
import static com.uber.nullaway.NullabilityUtil.isArrayElementNullable;
@@ -336,12 +336,7 @@ private boolean isCallToUnmarkedMethod(ExpressionTree expr) {
336336
return false;
337337
}
338338

339-
Symbol.MethodSymbol methodSymbol = getSymbolForMethodInvocation(methodInvoke);
340-
341-
if (methodSymbol == null) {
342-
return false;
343-
}
344-
339+
Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(methodInvoke);
345340
return codeAnnotationInfo.isSymbolUnannotated(methodSymbol, config, handler);
346341
}
347342

@@ -429,40 +424,19 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
429424
if (!withinAnnotatedCode(state)) {
430425
return Description.NO_MATCH;
431426
}
432-
Symbol.MethodSymbol methodSymbol = getSymbolForMethodInvocation(tree);
427+
Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
433428
handler.onMatchMethodInvocation(tree, new MethodAnalysisContext(this, state, methodSymbol));
434429
// assuming this list does not include the receiver
435430
List<? extends ExpressionTree> actualParams = tree.getArguments();
436431
return handleInvocation(tree, state, methodSymbol, actualParams);
437432
}
438433

439-
private static Symbol.MethodSymbol getSymbolForMethodInvocation(MethodInvocationTree tree) {
440-
Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
441-
Verify.verify(methodSymbol != null, "not expecting unresolved method here");
442-
// In certain cases, we need to get the base symbol for the method rather than the symbol
443-
// attached to the call.
444-
// For interface methods, if the method is an implicit method corresponding to a method from
445-
// java.lang.Object, the base symbol is for the java.lang.Object method. We need this to
446-
// properly treat the method as unannotated, which is particularly important for equals()
447-
// methods. This is an adaptation to a change in JDK 18; see
448-
// https://bugs.openjdk.org/browse/JDK-8272564
449-
// Also, sometimes we need the base symbol to properly deal with static imports; see
450-
// https://github.com/uber/NullAway/issues/764
451-
// We can remove this workaround once we require the version of Error Prone released after
452-
// 2.24.1, to get
453-
// https://github.com/google/error-prone/commit/e5a6d0d8f9f96bda8e9952b7817cd0d2b63e51be
454-
return (Symbol.MethodSymbol) methodSymbol.baseSymbol();
455-
}
456-
457434
@Override
458435
public Description matchNewClass(NewClassTree tree, VisitorState state) {
459436
if (!withinAnnotatedCode(state)) {
460437
return Description.NO_MATCH;
461438
}
462439
Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
463-
if (methodSymbol == null) {
464-
throw new RuntimeException("not expecting unresolved method here");
465-
}
466440
ExpressionTree enclosingExpression = tree.getEnclosingExpression();
467441
if (enclosingExpression != null) {
468442
// technically this is not a dereference; there is a requireNonNull() call in the
@@ -1275,7 +1249,7 @@ private Symbol.ClassSymbol enclosingClassSymbol(TreePath enclosingBlockPath) {
12751249
Tree parent = enclosingBlockPath.getParentPath().getLeaf();
12761250
return ASTHelpers.getSymbol((ClassTree) parent);
12771251
} else {
1278-
return castToNonNull(ASTHelpers.enclosingClass(ASTHelpers.getSymbol(leaf)));
1252+
return castToNonNull(ASTHelpers.enclosingClass(castToNonNull(ASTHelpers.getSymbol(leaf))));
12791253
}
12801254
}
12811255

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package com.uber.nullaway.dataflow;
1717

1818
import static com.google.common.base.Preconditions.checkNotNull;
19-
import static com.uber.nullaway.ASTHelpersBackports.isStatic;
19+
import static com.google.errorprone.util.ASTHelpers.isStatic;
2020
import static com.uber.nullaway.NullabilityUtil.castToNonNull;
2121
import static com.uber.nullaway.Nullness.BOTTOM;
2222
import static com.uber.nullaway.Nullness.NONNULL;

0 commit comments

Comments
 (0)