Repository navigation
Stuck with 2.4.0 and JDK 11 due to Lombok warnings #3094
Description
Hi everyone,
I'm facing an issue with ErrorProne currently that is making it harder to upgrade from JDK 11 to 17.
In short, ErrorProne 2.4.0 with JDK 11 works well for me, but I cannot use 2.4.0 with JDK 17, and when I upgrade to anything newer than 2.4.0 I get crazy amounts of warnings for Lombok annotations.
Here is a minimal reproducer - just a single class with a single "@lombok.Value" annotation (use JDK 11 with this):
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mihalyr.test</groupId>
<artifactId>errorprone-test</artifactId>
<version>1.0-SNAPSHOT</version>
<name>errorprone-test</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<errorprone.version>2.12.1</errorprone.version>
<lombok.version>1.18.22</lombok.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne -XepDisableWarningsInGeneratedCode</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${errorprone.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
src/main/java/errorprone/App.java
package errorprone;
@lombok.Value
public class App {
String greeting;
public void run() {
System.out.println(greeting);
}
public static void main(String[] args) {
new App("hello!").run();
}
}lombok.config
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = trueCase 1: ErrorProne 2.4.0 and JDK 11
Everything is working as expected.
Maven output
➜ errorprone-2.5 mvn clean compile --show-version -Derrorprone.version=2.4.0
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /home/mihalyr/.sdkman/candidates/maven/current
Java version: 11.0.14, vendor: Eclipse Adoptium, runtime: /home/mihalyr/.sdkman/candidates/java/11.0.14-tem
Default locale: en_IE, platform encoding: UTF-8
OS name: "linux", version: "5.16.18-100.fc34.x86_64", arch: "amd64", family: "unix"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.mihalyr.test:errorprone-2.5 >-------------------
[INFO] Building errorprone-2.5 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ errorprone-2.5 ---
[INFO] Deleting /home/mihalyr/workspace/errorprone-2.5/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ errorprone-2.5 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/mihalyr/workspace/errorprone-2.5/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ errorprone-2.5 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/mihalyr/workspace/errorprone-2.5/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.510 s
[INFO] Finished at: 2022-04-10T20:54:04+02:00
[INFO] ------------------------------------------------------------------------
Case 2: ErrorProne 2.5.0 and JDK 11
This fails with the below error:
[ERROR] java.lang.NoSuchMethodError: 'com.sun.tools.javac.util.List com.sun.tools.javac.code.Symbol$TypeSymbol.getEnclosedElements()'
Case 3: ErrorProne 2.5.1 and JDK 11
The Lombok warnings start here.
Maven output
➜ errorprone-2.5 mvn clean compile --show-version -Derrorprone.version=2.5.1
Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /home/mihalyr/.sdkman/candidates/maven/current
Java version: 11.0.14, vendor: Eclipse Adoptium, runtime: /home/mihalyr/.sdkman/candidates/java/11.0.14-tem
Default locale: en_IE, platform encoding: UTF-8
OS name: "linux", version: "5.16.18-100.fc34.x86_64", arch: "amd64", family: "unix"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.mihalyr.test:errorprone-2.5 >-------------------
[INFO] Building errorprone-2.5 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ errorprone-2.5 ---
[INFO] Deleting /home/mihalyr/workspace/errorprone-2.5/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ errorprone-2.5 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/mihalyr/workspace/errorprone-2.5/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ errorprone-2.5 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/mihalyr/workspace/errorprone-2.5/target/classes
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[5,11] [SameNameButDifferent] The name `greeting;` refers to [java.lang.SuppressWarnings, java.lang.String] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[5,11] [SameNameButDifferent] The name `greeting;` refers to [java.lang.SuppressWarnings, java.lang.String] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.525 s
[INFO] Finished at: 2022-04-10T20:54:52+02:00
[INFO] ------------------------------------------------------------------------
Case 4: ErrorProne 2.4.0 and JDK 17
This does not work, fails with the following:
[ERROR] java.lang.NoSuchMethodError: 'java.lang.Iterable com.sun.tools.javac.code.Scope$WriteableScope.getSymbolsByName(com.sun.tools.javac.util.Name, com.sun.tools.javac.util.Filter)'
Case 5: ErrorProne 2.12.1 (or any >= 2.5.1) and JDK 17
This throws a bunch of warnings again.
Maven output
➜ errorprone-2.5 MAVEN_OPTS="--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED" mvn clean compile -Derrorprone.version=2.12.1
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.mihalyr.test:errorprone-2.5 >-------------------
[INFO] Building errorprone-2.5 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ errorprone-2.5 ---
[INFO] Deleting /home/mihalyr/workspace/errorprone-2.5/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ errorprone-2.5 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/mihalyr/workspace/errorprone-2.5/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ errorprone-2.5 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/mihalyr/workspace/errorprone-2.5/target/classes
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[3] [SameNameButDifferent] The name `@lombok.Value` refers to [java.lang.SuppressWarnings, java.lang.String, java.lang.Override, java.lang.Object] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[5,11] [SameNameButDifferent] The name `greeting;` refers to [java.lang.SuppressWarnings, java.lang.String] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[WARNING] /home/mihalyr/workspace/errorprone-2.5/src/main/java/errorprone/App.java:[5,11] [SameNameButDifferent] The name `greeting;` refers to [java.lang.SuppressWarnings, java.lang.String] within this file. It may be confusing to have the same name refer to multiple types. Consider qualifying them for clarity.
(see https://errorprone.info/bugpattern/SameNameButDifferent)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.502 s
[INFO] Finished at: 2022-04-10T20:59:47+02:00
[INFO] ------------------------------------------------------------------------
I've also tried the following Lombok configuration (added new dependency for @SuppressFBWarnings com.github.spotbugs:spotbugs-annotations:4.6.0):
lombok.config
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
lombok.extern.findbugs.addSuppressFBWarnings = true
lombok.addSuppressWarnings = trueDumping 15 warnings for every single Lombok annotation doesn't seem to be right. In our production code the amount of warnings is just too much, so far I kept staying with JDK 11 and 2.4.0, but I would really like to upgrade to JDK 17.
I was considering disabling all warnings temporarily, but adding -XepDisableAllWarnings didn't change anything, the warnings remained. It works when I disable or suppress SameNameBugDifferent explicitly. I could only do that globally, because suppressing every single case on production adds a lot of unnecessary noise to the code. However, this is not the only Lombok annotation that throws warnings.
I can switch from @Value to @AllArgsConstructor for example and I get the same warnings but less of them, only 4. But If I add @Data in addition, I get 33 warnings already from this simple piece of code.
I am using the exact same Lombok version that worked with 2.4.0, it uses the @lombok.Generated annotation and I use ErrorProne with the -XepDisableWarningsInGeneratedCode as before, the only change is ErrorProne version from 2.4.0 to 2.5.1.
Did anything change in ErrorProne in 2.5.0 or 2.5.1 that could be the culprit of this?
Is there any workaround I could use other than disabling any check that is being thrown or suppressing with annotations? Something like telling ErrorProne a list of annotations to ignore (a way to pass a list of lombok annotations that it should skip)?
Or did I miss or forgot something obvious that needs to be done when upgrading from 2.4.0 to 2.5.x? Please let me know if there is anything else I can try.
Thank you in advance.
Activity
tbroyer commentedon Apr 10, 2022
I would say that once again Lombok generates an invalid (and unexpected) AST that ErrorProne fails to process.
Judging by the reported name (
@lombok.Value, where the message is supposed to display a simple name) and how it's retrieved/computed (getSourceForNode), and the names listed as what it refers to, I'd say that Lombok links every AST node it generates with the source code position of the@lombok.Valueannotation rather than no position at all.There have been issues with previous versions of ErrorProne where "no position" caused errors which may explain Lombok's behavior.
mihalyr commentedon Apr 11, 2022
@tbroyer Thank you for your looking into it. So far what I see is that the same Lombok version was working fine with ErrorProne 2.4.0, and without any changes in Lombok, it is not working with ErrorProne 2.5.x and above. In case this is a Lombok problem, it seems that it was there all the time, but somehow ErrorProne 2.4.0 was able to handle it, or somehow ignored or hid this issue from us.
Even if there is a problem with Lombok, shouldn't it be ignored because of the
@Generatedannotations and the-XepDisableWarningsInGeneratedCodeflag?Would you recommend opening an issue also on the Lombok side to tackle this from both directions?
cushon commentedon Apr 11, 2022
Looking at this case in a debugger seems to confirm that. I think this was the corresponding change: Rawi01/lombok@5ec517d. Previously it was adding synthetic AST nodes without source position information, and now it uses the source position information as the lombok annotation associated with the generated code.
mihalyr commentedon Apr 11, 2022
My workaround, that seems to work for me currently is to use the Lombok Maven Plugin and delombok the sources into a new folder and I'll use those generated sources as input for the compiler. When ErrorProne is running against the delombok'd sources, it seems to work as expected, no extra warnings.
I have the following in my
pom.xmldelombok profile
In my parent
pom.xmlI have this:parent pom config
I still have the original maven compiler + errorprone + lombok configuration as the default, this allows me to load the project into IntelliJ with the original source folders and don't have to deal with delombok in IDEA (it will generate the warnings there though, but it seems a bit more manageable). And I had to point checkstyle and PMD to the original sources
${defaultSourceDirectory}to tell them not to check the delombok'd files.I've also added
-Pdelombokinto.mvn/maven.configto activate the profile by default, but keep it out of way for IntelliJ imports.At the moment this configuration seems to work for me and I can use JDK 17, ErrorProne 2.12.1 and Lombok 1.18.22, all the latest. However, haven't tested it yet extensively, just enabled on a new project while I figured things out.
cushon commentedon Apr 12, 2022
I think that the delombok approach is more principled--instead of modifying the AST in place (which breaks source position information), it just makes it a separate preprocessor that doesn't affect other tools running during the compilation.
It is maybe a little harder to integrate into builds, though, I'm sure there are reasons not all lombok users are using delombok.
We could also consider trying to tolerate ASTs with broken source position information more gracefully. The generated methods here look something like:
In theory Error Prone could recognize
@lombok.Generatedor@SuppressWarnings("all")and treat them as suppressions (except maybe for undisableable checks). That might help with our backlog of lombok-related crashes.mihalyr commentedon Apr 13, 2022
@cushon this is not theory, ErrorProne does have the a flag to recognize and ignore any
@Generatedannotations regardless of the full class name, see https://errorprone.info/docs/flagsNow that I look into it, it seems that you added that feature to check only the simple name of the annotation 🙂 4d6a0cc
Here is more when I look into various Lombok versions (I am working with Java 11 here, so only tested Lombok >= 1.18):
I am not sure how did I test before but Lombok >= 1.18.18 shows warnings also with ErrorProne 2.4.0 now just as with ErrorProne 1.18.22 on Java 11...
So there is a sweet spot with latest ErrorProne 2.12.1 with Lombok 1.18.16 on JDK 11 that works for me.
But now the problem is with JDK 17 it seems, for which I need Lombok >= 1.18.22 to work, but that will throw me the warnings again.
It seems that something changed with Lombok 1.18.18 that led to these new warnings shown by ErrorProne.
What should be the next step here?
@lombok.Generatedis not ignored byXepDisableWarningsInGeneratedCodein the new Lombok versions?mihalyr commentedon Apr 13, 2022
I've checked locally and can confirm that this issue was introduced with the commit @cushon mentioned above: projectlombok/lombok@a234a8e
cushon commentedon Apr 13, 2022
We do have some logic that looks for the simple name
Generated:error-prone/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java
Line 1557 in 7b6ae68
But I think
-XepDisableWarningsInGeneratedCodecurrently only recognizesjavax.annotation.Generatedandjavax.annotation.processing.Generated:error-prone/check_api/src/main/java/com/google/errorprone/SuppressionInfo.java
Line 63 in 7b6ae68
Additionally, there are a couple of different code paths for testing suppressions, and the one
SameNameButDifferentis using doesn't handle-XepDisableWarningsInGeneratedCode:error-prone/core/src/main/java/com/google/errorprone/bugpatterns/SameNameButDifferent.java
Line 60 in 7b6ae68
error-prone/check_api/src/main/java/com/google/errorprone/bugpatterns/BugChecker.java
Lines 266 to 269 in 7b6ae68
I'll look at cleaning some of this up on our side. In general there's a limit to what I'm prepared to do to try to handle invalid ASTs with broken source position information gracefully, but fixing the
-XepDisableWarningsInGeneratedCodeissues that have been uncovered here seems beneficial for everyone.Handle all annotations with the simple name `Generated` in `-XepDisab…
Handle all annotations with the simple name `Generated` in `-XepDisab…
Reconcile `BugChecker#isSuppressed` with suppression handling in `Err…
Reconcile `BugChecker#isSuppressed` with suppression handling in `Err…
cushon commentedon Apr 13, 2022
With 47c2b05 and 5d647de,
-XepDisableWarningsInGeneratedCodeshould do a better job of disabling the check that's crashing on Lombok in this compilation.mihalyr commentedon Apr 14, 2022
Compiling with ErrorProne before your changes (7b6ae68) gives me the warnings:
Maven output
Compiling with ErrorProne after your changes (5d647de) gives no warnings anymore!
Maven output
Also tested that not adding
lombok.addLombokGeneratedAnnotation = trueto Lombok config, or not adding-XepDisableWarningsInGeneratedCodeflag for ErrorProne, both will show warnings as expected.I've tested this with both ErrorProne and the test project built with JDK17, with latest Lombok 1.18.22 and I can confirm that the behavior reported in the ticket has been fixed.
@cushon you're amazing! Your help is much appreciated! Thank you!
mihalyr commentedon Apr 14, 2022
@cushon just a last question, I'm not familiar with ErrorProne release cycles, is it possible to know when will be this patch released?
cushon commentedon Apr 14, 2022
@mihalyr I have performed a release that includes those fixes.
hakanai commentedon May 10, 2022
Reading the comments here, I too tried Lombok 1.18.16 to see if that would get us out of this mess, but it ended up failing at
SameNameButDifferentin the same way as the previous version.So I tried Lombok 1.18.24, and that then seems to get us through compiling the first module in our codebase - so that's progress.
SameNameButDifferentnow only emits a warning, claiming that "The name@Builderrefers to [javax.annotation.Nonnull, javax.annotation.Nullable] within this file. It may be confusing..." That is indeed confusing - so confusing that I have no idea how to interpret the error message.The new failure we get is because
MissingSummary(which we upgrade to ERROR) picks up the methods@Buildergenerates as not having summary docs. Oddly, errorprone v2.4.0 either doesn't have that issue, or fails to pick them up due to a different [favourable] bug.But we turn off warnings on generated code, so why it's even checking these is a mystery. It could be that #3108 will fix it and we're just waiting for that.