Skip to content

Stuck with 2.4.0 and JDK 11 due to Lombok warnings #3094

Closed

Description

@mihalyr

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 = true

Case 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 = true

Dumping 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

  1. tbroyer commented on Apr 10, 2022

    @tbroyer
    Contributor

    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.Value annotation 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.

  2. mihalyr commented on Apr 11, 2022

    @mihalyr
    Author

    @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 @Generated annotations and the -XepDisableWarningsInGeneratedCode flag?

    Would you recommend opening an issue also on the Lombok side to tackle this from both directions?

  3. cushon commented on Apr 11, 2022

    @cushon
    Collaborator

    I'd say that Lombok links every AST node it generates with the source code position of the @lombok.Value annotation rather than no position at all

    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.

  4. mihalyr commented on Apr 11, 2022

    @mihalyr
    Author

    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.xml

    delombok profile
      <profiles>
        <profile>
          <id>delombok</id>
          <!-- ErrorProne >= 2.7 is needed for JDK 17, but ErrorProne >= 2.5.0 has a problem with Lombok warnings
               see https://github.com/google/error-prone/issues/3094
    
               The workaround here is to first delombok the code before compiling. Since we don't want to use a separate
               folder for Lombok source files, which would be quite inconvenient, we tell the Lombok plugin to use the
               regular source files from 'src/main/java' and then tell Maven to consider the folder with the delobmok
               output as the main sourceDirectory.
               see https://github.com/awhitford/lombok.maven/issues/7#issuecomment-136607499
    
               This configuration is applied in a profile that we can invoke from the command line, this way IntelliJ
               is able to work with the sources normally without knowing that that we use delombok and having to make
               overrides in the project.
          -->
          <properties>
            <!-- Do not use 'target/generated-sources/delombok', we don't want IntelliJ to recognize it as a source folder,
                 it would lead to errors that need manual workaround on each project reload. -->
            <lombok.outputDirectory>${project.build.outputDirectory}/target/delombok/generated-sources</lombok.outputDirectory>
            <overrideSourceDirectory>${lombok.outputDirectory}</overrideSourceDirectory>
          </properties>
          <build>
            <plugins>
              <!-- Delombok sources before build -->
              <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
                <executions>
                  <execution>
                    <phase>generate-sources</phase>
                    <goals>
                      <goal>delombok</goal>
                    </goals>
                    <configuration>
                      <addOutputDirectory>false</addOutputDirectory>
                      <sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
              <!-- Maven Compiler configuration with ErrorProne, without Lombok -->
              <!-- Keep this in sync with the default compiler plugin, except for the delombok annotation processor -->
              <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                  <forceJavacCompilerUse>true</forceJavacCompilerUse>
                  <showDeprecation>true</showDeprecation>
                  <showWarnings>true</showWarnings>
                  <compilerArgs>
                    <arg>-XDcompilePolicy=simple</arg>
                    <arg>-Xplugin:ErrorProne -XepDisableWarningsInGeneratedCode
                      -XepExcludedPaths:.*/target/generated-sources/.*|.*/src/test/java/.*
                      -Xep:NullAway:${nullaway.level} -XepOpt:NullAway:AnnotatedPackages=mypackages.*
                    </arg>
                  </compilerArgs>
                  <annotationProcessorPaths>
                    <path>
                      <groupId>com.google.errorprone</groupId>
                      <artifactId>error_prone_core</artifactId>
                      <version>${errorprone.version}</version>
                    </path>
                    <path>
                      <groupId>com.uber.nullaway</groupId>
                      <artifactId>nullaway</artifactId>
                      <version>${nullaway.version}</version>
                    </path>
                    <!-- Other annotation processors go here.
    
                    If 'annotationProcessorPaths' is set, processors will no longer be
                    discovered on the regular -classpath; see also 'Using Error Prone
                    together with other annotation processors' below. -->
                  </annotationProcessorPaths>
                </configuration>
              </plugin>
            </plugins>
          </build>
        </profile>
      </profiles>

    In my parent pom.xml I have this:

    parent pom config
      <properties>
        <!-- Allows to override the default source directory, e.g. for delombok -->
        <defaultSourceDirectory>${project.basedir}/src/main/java</defaultSourceDirectory>
        <overrideSourceDirectory>${defaultSourceDirectory}</overrideSourceDirectory>
      </properties>
      <build>
        <sourceDirectory>${overrideSourceDirectory}</sourceDirectory>

    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 -Pdelombok into .mvn/maven.config to 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.

  5. cushon commented on Apr 12, 2022

    @cushon
    Collaborator

    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:

        @java.lang.SuppressWarnings(value = "all")
        @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(justification = "generated code")
        @lombok.Generated()
        public Test(final String greeting) {
            super();
            this.greeting = greeting;
        }
    

    In theory Error Prone could recognize @lombok.Generated or @SuppressWarnings("all") and treat them as suppressions (except maybe for undisableable checks). That might help with our backlog of lombok-related crashes.

  6. mihalyr commented on Apr 13, 2022

    @mihalyr
    Author

    In theory Error Prone could recognize @lombok.Generated or @SuppressWarnings("all") and treat them as suppressions (except maybe for undisableable checks).

    @cushon this is not theory, ErrorProne does have the a flag to recognize and ignore any @Generated annotations regardless of the full class name, see https://errorprone.info/docs/flags

    -XepDisableWarningsInGeneratedCode : Disables warnings in classes annotated with @Generated

    Now 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):

    1. Lombok >= 1.18.0 <1.18.10 fails with the following:
    [ERROR]      error-prone version: 2.12.1
    [ERROR]      BugPattern: SameNameButDifferent
    [ERROR]      Stack Trace:
    [ERROR]      java.lang.IllegalArgumentException: invalid source positions (65, 64) for: String
    
    1. Lombok >= 1.18.10 < 1.18.18 DOES WORK with ErrorProne 2.12.1 with Java 11 (no extensive warnigns!)
    2. Lombok >= 1.18.18 shows those warnings again as in the description

    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?

    • Is there anything to do on the ErrorProne side for this issue? For example looking into why @lombok.Generated is not ignored by XepDisableWarningsInGeneratedCode in the new Lombok versions?
    • Would you recommend opening an issue for Lombok to see if there is anything on their side to fix here to make it work again with ErrorProne?
  7. mihalyr commented on Apr 13, 2022

    @mihalyr
    Author

    I've checked locally and can confirm that this issue was introduced with the commit @cushon mentioned above: projectlombok/lombok@a234a8e

  8. cushon commented on Apr 13, 2022

    @cushon
    Collaborator

    ErrorProne does have the a flag to recognize and ignore any @generated annotations regardless of the full class name

    We do have some logic that looks for the simple name Generated:

    .filter(attribute -> attribute.type.tsym.getSimpleName().contentEquals("Generated"))

    But I think -XepDisableWarningsInGeneratedCode currently only recognizes javax.annotation.Generated and javax.annotation.processing.Generated:

    Stream.of("javax.annotation.Generated", "javax.annotation.processing.Generated")

    Additionally, there are a couple of different code paths for testing suppressions, and the one SameNameButDifferent is using doesn't handle -XepDisableWarningsInGeneratedCode:

    private boolean isSuppressed(SuppressWarnings suppression) {
    return suppression != null
    && !Collections.disjoint(Arrays.asList(suppression.value()), allNames());
    }

    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 -XepDisableWarningsInGeneratedCode issues that have been uncovered here seems beneficial for everyone.

  9. cushon commented on Apr 13, 2022

    @cushon
    Collaborator

    With 47c2b05 and 5d647de, -XepDisableWarningsInGeneratedCode should do a better job of disabling the check that's crashing on Lombok in this compilation.

  10. mihalyr commented on Apr 14, 2022

    @mihalyr
    Author

    Compiling with ErrorProne before your changes (7b6ae68) gives me the warnings:

    Maven output
    [INFO] Scanning for projects...
    [INFO] 
    [INFO] ------------------< com.mihalyr.test:errorprone-test >------------------
    [INFO] Building errorprone-test 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ errorprone-test ---
    [INFO] Deleting /home/mihalyr/workspace/errorprone-2.5/target
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ errorprone-test ---
    [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-test ---
    [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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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, lombok.Generated, 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.679 s
    [INFO] Finished at: 2022-04-14T13:02:37+02:00
    [INFO] ------------------------------------------------------------------------
    
    

    Compiling with ErrorProne after your changes (5d647de) gives no warnings anymore!

    Maven output
    [INFO] Scanning for projects...
    [INFO] 
    [INFO] ------------------< com.mihalyr.test:errorprone-test >------------------
    [INFO] Building errorprone-test 1.0-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ errorprone-test ---
    [INFO] Deleting /home/mihalyr/workspace/errorprone-2.5/target
    [INFO] 
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ errorprone-test ---
    [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-test ---
    [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.540 s
    [INFO] Finished at: 2022-04-14T12:59:27+02:00
    [INFO] ------------------------------------------------------------------------
    

    Also tested that not adding lombok.addLombokGeneratedAnnotation = true to Lombok config, or not adding -XepDisableWarningsInGeneratedCode flag 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!

  11. mihalyr commented on Apr 14, 2022

    @mihalyr
    Author

    @cushon just a last question, I'm not familiar with ErrorProne release cycles, is it possible to know when will be this patch released?

  12. cushon commented on Apr 14, 2022

    @cushon
    Collaborator

    @mihalyr I have performed a release that includes those fixes.

  13. hakanai commented on May 10, 2022

    @hakanai

    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 SameNameButDifferent in 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. SameNameButDifferent now only emits a warning, claiming that "The name @Builder refers 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 @Builder generates 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions