From 18cfa8bd92cc0548b04e4c7a0dd12c936f06e9bc Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Fri, 8 Dec 2023 09:20:35 -0800 Subject: [PATCH 1/5] WIP --- .../uber/nullaway/handlers/LombokHandler.java | 22 ------------------- test-java-lib-lombok/build.gradle | 4 ++++ test-java-lib-lombok/lombok.config | 1 + 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/nullaway/src/main/java/com/uber/nullaway/handlers/LombokHandler.java b/nullaway/src/main/java/com/uber/nullaway/handlers/LombokHandler.java index 7d76611b9d..7069497800 100644 --- a/nullaway/src/main/java/com/uber/nullaway/handlers/LombokHandler.java +++ b/nullaway/src/main/java/com/uber/nullaway/handlers/LombokHandler.java @@ -86,26 +86,4 @@ public Nullness onOverrideMethodReturnNullability( } return returnNullness; } - - /** - * Mark the first argument of Lombok-generated {@code equals} methods as {@code @Nullable}, since - * Lombok does not generate the annotation. - */ - @Override - public Nullness[] onOverrideMethodInvocationParametersNullability( - VisitorState state, - Symbol.MethodSymbol methodSymbol, - boolean isAnnotated, - Nullness[] argumentPositionNullness) { - if (ASTHelpers.hasAnnotation(methodSymbol, LOMBOK_GENERATED_ANNOTATION_NAME, state)) { - // We assume that Lombok-generated equals methods with a single argument override - // Object.equals and are not an overload. - if (methodSymbol.getSimpleName().contentEquals("equals") - && methodSymbol.params().size() == 1) { - // The parameter is not annotated with @Nullable, but it should be. - argumentPositionNullness[0] = Nullness.NULLABLE; - } - } - return argumentPositionNullness; - } } diff --git a/test-java-lib-lombok/build.gradle b/test-java-lib-lombok/build.gradle index c70f54828d..9de7a22eff 100644 --- a/test-java-lib-lombok/build.gradle +++ b/test-java-lib-lombok/build.gradle @@ -44,3 +44,7 @@ tasks.withType(JavaCompile) { "--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED" ] } + +tasks.named('compileJava') { + inputs.file('lombok.config') +} diff --git a/test-java-lib-lombok/lombok.config b/test-java-lib-lombok/lombok.config index df71bb6a0f..1f5615e913 100644 --- a/test-java-lib-lombok/lombok.config +++ b/test-java-lib-lombok/lombok.config @@ -1,2 +1,3 @@ config.stopBubbling = true lombok.addLombokGeneratedAnnotation = true +lombok.addNullAnnotations = javax \ No newline at end of file From 7506f2d3b9a3034f2e1b527625d56dfd12e40a4e Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Fri, 8 Dec 2023 09:30:27 -0800 Subject: [PATCH 2/5] tweak Lombok docs --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 13769974d7..ee37823b11 100644 --- a/README.md +++ b/README.md @@ -80,13 +80,13 @@ Unlike other annotation processors above, Lombok modifies the in-memory AST of t We do not particularly recommend using NullAway with Lombok. However, NullAway encodes some knowledge of common Lombok annotations and we do try for best-effort compatibility. In particular, common usages like `@lombok.Builder` and `@Data` classes should be supported. -In order for NullAway to successfully detect Lombok generated code within the in-memory Java AST, the following configuration option must be passed to Lombok as part of an applicable `lombok.config` file: +For the best compatibility with NullAway, add the following configuration options to an applicable `lombok.config` file: ``` -addLombokGeneratedAnnotation +lombok.addLombokGeneratedAnnotation = true +lombok.addNullAnnotations = ``` - -This causes Lombok to add `@lombok.Generated` to the methods/classes it generates. NullAway will ignore (i.e. not check) the implementation of this generated code, treating it as unannotated. +See the [Lombok configuration documentation](https://projectlombok.org/features/configuration) for more details. The `addLombokGeneratedAnnotation` option causes Lombok to add `@lombok.Generated` to the methods/classes it generates. NullAway will ignore (i.e. not check) the implementation of this generated code, treating it as unannotated. The `addNullAnnotations` options causes Lombok to add nullability annotations to its generated code, which can remove certain NullAway false positives. In particular, with this option enabled, Lombok adds a `@Nullable` annotation to the parameter of every generated `equals()` method, and then NullAway will not warn if a `@Nullable` argument is passed to such a method. ## Code Example From 11d6f10fe36db25d917d8a035b901f9d79256309 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Fri, 8 Dec 2023 09:31:47 -0800 Subject: [PATCH 3/5] trailing newline --- test-java-lib-lombok/lombok.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-java-lib-lombok/lombok.config b/test-java-lib-lombok/lombok.config index 1f5615e913..e94be7803d 100644 --- a/test-java-lib-lombok/lombok.config +++ b/test-java-lib-lombok/lombok.config @@ -1,3 +1,3 @@ config.stopBubbling = true lombok.addLombokGeneratedAnnotation = true -lombok.addNullAnnotations = javax \ No newline at end of file +lombok.addNullAnnotations = javax From d0331bb71e0c8358493ca98f80a93d87232af672 Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Fri, 8 Dec 2023 09:32:32 -0800 Subject: [PATCH 4/5] comment --- test-java-lib-lombok/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/test-java-lib-lombok/build.gradle b/test-java-lib-lombok/build.gradle index 9de7a22eff..0652b7e4ac 100644 --- a/test-java-lib-lombok/build.gradle +++ b/test-java-lib-lombok/build.gradle @@ -45,6 +45,7 @@ tasks.withType(JavaCompile) { ] } +// Needed so that compilation re-runs if the lombok.config is changed tasks.named('compileJava') { inputs.file('lombok.config') } From c25e4bfacb74550787a1693ba5ed84c5f0bad73c Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Fri, 8 Dec 2023 09:52:56 -0800 Subject: [PATCH 5/5] bump lombok --- gradle/dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 26fc151bd8..1786ed3790 100755 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -109,7 +109,7 @@ def test = [ rxjava2 : "io.reactivex.rxjava2:rxjava:2.1.2", commonsLang3 : "org.apache.commons:commons-lang3:3.8.1", commonsLang : "commons-lang:commons-lang:2.6", - lombok : "org.projectlombok:lombok:1.18.24", + lombok : "org.projectlombok:lombok:1.18.30", springBeans : "org.springframework:spring-beans:5.3.7", springContext : "org.springframework:spring-context:5.3.7", grpcCore : "io.grpc:grpc-core:1.15.1", // Should upgrade, but this matches our guava version