diff --git a/build.gradle b/build.gradle index 5ccd8b0ed6..d90b7ac789 100644 --- a/build.gradle +++ b/build.gradle @@ -42,10 +42,30 @@ repositories { apply from: "gradle/dependencies.gradle" +// Returns true if the project's purpose is to test a NullAway build outside of unit tests or is a sample project +boolean isTestProject(Project p) { + def testProjs = [ + "test-java-lib", + "test-java-lib-lombok", + "test-library-models", + "sample", + "sample-app" + ] + return testProjs.contains(p.name) +} + subprojects { project -> project.apply plugin: "net.ltgt.errorprone" - project.dependencies { - errorprone deps.build.errorProneCore + if (isTestProject(project)) { + // Compile the project using the same Error Prone version as the API dependence. This way, we test that we can + // still compile the project with old Error Prone versions. + project.dependencies { + errorprone deps.build.errorProneCoreForApi + } + } else { + project.dependencies { + errorprone deps.build.errorProneCore + } } project.tasks.withType(JavaCompile) { dependsOn(installGitHooks) @@ -60,8 +80,6 @@ subprojects { project -> disableWarningsInGeneratedCode = true // this check is too noisy check("StringSplitter", CheckSeverity.OFF) - // https://github.com/google/error-prone/issues/3366 - check("CanIgnoreReturnValueSuggester", CheckSeverity.OFF) // turn up various checks check("WildcardImport", CheckSeverity.ERROR) check("MissingBraces", CheckSeverity.ERROR) diff --git a/nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java b/nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java index e60b798a9d..25a08d7cb2 100755 --- a/nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java +++ b/nullaway/src/main/java/com/uber/nullaway/ErrorBuilder.java @@ -129,9 +129,10 @@ public Description createErrorDescription( checkName = INITIALIZATION_CHECK_NAME; } - // Mildly expensive state.getPath() traversal, occurs only once per potentially - // reported error. - if (hasPathSuppression(state.getPath(), checkName)) { + // Mildly expensive state.getPath() traversal, occurs twice per potentially reported error. We + // can get rid of the check for "all" once we require Error Prone 2.22.0 or higher. + TreePath path = state.getPath(); + if (hasPathSuppression(path, checkName) || hasPathSuppression(path, "all")) { return Description.NO_MATCH; } diff --git a/test-java-lib-lombok/build.gradle b/test-java-lib-lombok/build.gradle index c70f54828d..a590c7f42e 100644 --- a/test-java-lib-lombok/build.gradle +++ b/test-java-lib-lombok/build.gradle @@ -36,6 +36,13 @@ tasks.withType(JavaCompile) { check("NullAway", CheckSeverity.ERROR) option("NullAway:AnnotatedPackages", "com.uber") option("NullAway:UnannotatedSubPackages", "com.uber.lib.unannotated") + if (deps.versions.errorProneApi != deps.versions.errorProneLatest) { + // These checks are incompatible with Lombok in older Error Prone versions, so disable them + check("MissingBraces", CheckSeverity.OFF) + check("SameNameButDifferent", CheckSeverity.OFF) + check("MissingOverride", CheckSeverity.OFF) + check("MissingSummary", CheckSeverity.OFF) + } } } // We need to fork on JDK 16+ since Lombok accesses internal compiler APIs diff --git a/test-java-lib-lombok/src/main/java/com/uber/lombok/SimpleDataSub.java b/test-java-lib-lombok/src/main/java/com/uber/lombok/SimpleDataSub.java new file mode 100644 index 0000000000..1fab1b8397 --- /dev/null +++ b/test-java-lib-lombok/src/main/java/com/uber/lombok/SimpleDataSub.java @@ -0,0 +1,11 @@ +package com.uber.lombok; + +import javax.annotation.Nullable; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = false) +public class SimpleDataSub extends SimpleDataSuper { + @Nullable private String field2; +} diff --git a/test-java-lib-lombok/src/main/java/com/uber/lombok/SimpleDataSuper.java b/test-java-lib-lombok/src/main/java/com/uber/lombok/SimpleDataSuper.java new file mode 100644 index 0000000000..d3241c6f67 --- /dev/null +++ b/test-java-lib-lombok/src/main/java/com/uber/lombok/SimpleDataSuper.java @@ -0,0 +1,9 @@ +package com.uber.lombok; + +import javax.annotation.Nullable; +import lombok.Data; + +@Data +public class SimpleDataSuper { + @Nullable private String field1; +}