error-prone: Q: How analyze compiler crash?

My first attempts with error prone: on Windows 10, OpenJDK 17 17.0.5, maven wrapper 3.8.6, maven-compiler-plugin 3.10.1, 2290 source classes. The compiler mojo ends up with error without error messages:

Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1314)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:198)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)

How can I approach the cause of the error? Is there a debug logging? Can the code checks be activated individually to identify the faulty check?

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 19 (12 by maintainers)

Most upvoted comments

@Stephan202 Thank you, -X -Dmaven.compiler.verbose=true sort of helped. At least it made me take another (closer) look at the output of the compiler plugin.

I used it to compare the runs with toolchains plugin and without, especially the command-line options for javac. The interesting observation is that the command apparently gets messed up when the toolchains plugin is involved.

For better readability, I added a few line-breaks.

Output without toolchains plugin:

-d <project-root>/target/classes
-classpath <project-root>/target/classes:<user-home>/.m2/repository/org/projectlombok/lombok/1.18.26/lombok-1.18.26.jar:
-sourcepath <project-root>/src/main/java:<project-root>/target/generated-sources/annotations:
-s <project-root>/target/generated-sources/annotations
-processorpath <user-home>/.m2/repository/com/google/errorprone/error_prone_core/2.18.0/error_prone_core-2.18.0.jar:<user-home>/.m2/repository/com/google/errorprone/error_prone_annotation/2.18.0/error_prone_annotation-2.18.0.jar:<user-home>/.m2/repository/com/google/errorprone/error_prone_type_annotations/2.18.0/error_prone_type_annotations-2.18.0.jar:<user-home>/.m2/repository/com/google/errorprone/error_prone_check_api/2.18.0/error_prone_check_api-2.18.0.jar:<user-home>/.m2/repository/io/github/java-diff-utils/java-diff-utils/4.0/java-diff-utils-4.0.jar:<user-home>/.m2/repository/org/eclipse/jgit/org.eclipse.jgit/4.4.1.201607150455-r/org.eclipse.jgit-4.4.1.201607150455-r.jar:<user-home>/.m2/repository/com/github/kevinstern/software-and-algorithms/1.0/software-and-algorithms-1.0.jar:<user-home>/.m2/repository/com/github/ben-manes/caffeine/caffeine/3.0.5/caffeine-3.0.5.jar:<user-home>/.m2/repository/org/pcollections/pcollections/3.1.4/pcollections-3.1.4.jar:<user-home>/.m2/repository/com/google/guava/guava/31.0.1-jre/guava-31.0.1-jre.jar:<user-home>/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:<user-home>/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:<user-home>/.m2/repository/org/checkerframework/checker-qual/3.12.0/checker-qual-3.12.0.jar:<user-home>/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar:<user-home>/.m2/repository/com/google/auto/auto-common/1.2.1/auto-common-1.2.1.jar:<user-home>/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:<user-home>/.m2/repository/org/checkerframework/dataflow-errorprone/3.27.0/dataflow-errorprone-3.27.0.jar:<user-home>/.m2/repository/com/google/auto/value/auto-value-annotations/1.9/auto-value-annotations-1.9.jar:<user-home>/.m2/repository/com/google/errorprone/error_prone_annotations/2.18.0/error_prone_annotations-2.18.0.jar:<user-home>/.m2/repository/com/google/protobuf/protobuf-java/3.19.2/protobuf-java-3.19.2.jar:<user-home>/.m2/repository/com/google/auto/service/auto-service-annotations/1.0.1/auto-service-annotations-1.0.1.jar:<user-home>/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar:<user-home>/.m2/repository/org/projectlombok/lombok/1.18.26/lombok-1.18.26.jar:
-g
-verbose
--release 17
-encoding UTF-8
-XDcompilePolicy=simple
-Xplugin:ErrorProne

When the toolchains plugin is involved, the output looks as follows:

-d <project-root>/target/classes
-classpath <project-root>/target/classes:<user-home>/.m2/repository/org/projectlombok/lombok/1.18.26/lombok-1.18.26.jar:
-sourcepath <project-root>/src/main/java:<project-root>/target/generated-sources/annotations:
<project-root>/src/main/java/ShortSet.java <project-root>/src/main/java/LombokTestClass.java
-s <project-root>/target/generated-sources/annotations
-processorpath <user-home>/.m2/repository/com/google/errorprone/error_prone_core/2.18.0/error_prone_core-2.18.0.jar:<user-home>/.m2/repository/com/google/errorprone/error_prone_annotation/2.18.0/error_prone_annotation-2.18.0.jar:<user-home>/.m2/repository/com/google/errorprone/error_prone_type_annotations/2.18.0/error_prone_type_annotations-2.18.0.jar:<user-home>/.m2/repository/com/google/errorprone/error_prone_check_api/2.18.0/error_prone_check_api-2.18.0.jar:<user-home>/.m2/repository/io/github/java-diff-utils/java-diff-utils/4.0/java-diff-utils-4.0.jar:<user-home>/.m2/repository/org/eclipse/jgit/org.eclipse.jgit/4.4.1.201607150455-r/org.eclipse.jgit-4.4.1.201607150455-r.jar:<user-home>/.m2/repository/com/github/kevinstern/software-and-algorithms/1.0/software-and-algorithms-1.0.jar:<user-home>/.m2/repository/com/github/ben-manes/caffeine/caffeine/3.0.5/caffeine-3.0.5.jar:<user-home>/.m2/repository/org/pcollections/pcollections/3.1.4/pcollections-3.1.4.jar:<user-home>/.m2/repository/com/google/guava/guava/31.0.1-jre/guava-31.0.1-jre.jar:<user-home>/.m2/repository/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar:<user-home>/.m2/repository/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar:<user-home>/.m2/repository/org/checkerframework/checker-qual/3.12.0/checker-qual-3.12.0.jar:<user-home>/.m2/repository/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar:<user-home>/.m2/repository/com/google/auto/auto-common/1.2.1/auto-common-1.2.1.jar:<user-home>/.m2/repository/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar:<user-home>/.m2/repository/org/checkerframework/dataflow-errorprone/3.27.0/dataflow-errorprone-3.27.0.jar:<user-home>/.m2/repository/com/google/auto/value/auto-value-annotations/1.9/auto-value-annotations-1.9.jar:<user-home>/.m2/repository/com/google/errorprone/error_prone_annotations/2.18.0/error_prone_annotations-2.18.0.jar:<user-home>/.m2/repository/com/google/protobuf/protobuf-java/3.19.2/protobuf-java-3.19.2.jar:<user-home>/.m2/repository/com/google/auto/service/auto-service-annotations/1.0.1/auto-service-annotations-1.0.1.jar:<user-home>/.m2/repository/javax/inject/javax.inject/1/javax.inject-1.jar:<user-home>/.m2/repository/org/projectlombok/lombok/1.18.26/lombok-1.18.26.jar:
-g
-verbose
--release 17
-encoding UTF-8
-XDcompilePolicy=simple
-Xplugin:ErrorProne

Note the line between -sourcepath and -s: The source file paths get added in the middle of the javac command-line arguments, right before the arguments that seem to be specific to error-prone follow.

So, at least in my case, multi-line arguments for ErrorProne aren’t an issue.

I just wonder what causes that difference, and how to fix it (or if that actually is an issue at all).

Edit: After playing around a bit more, under the assumption that the plugin configuration itself shouldn’t be the problem since you got it working with a toolchain, I just tried another one – and it worked. Thus, the problem actually is the toolchain (configuration) itself. My configuration for Temurin JDK 17 and Temurin JDK 19 are both not working but Temurin JDK 11 and Microsoft OpenJDK 11 are.

Calling javac directly with JDK 17 or 19 leads to this error:

Exception in thread "main" java.lang.IllegalAccessError: class com.google.errorprone.BaseErrorProneJavaCompiler (in unnamed module @0x30c15d8b) cannot access class com.sun.tools.javac.api.BasicJavacTask (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.api to unnamed module @0x30c15d8b
	at com.google.errorprone.BaseErrorProneJavaCompiler.addTaskListener(BaseErrorProneJavaCompiler.java:95)
	at com.google.errorprone.ErrorProneJavacPlugin.init(ErrorProneJavacPlugin.java:34)
	at jdk.compiler/com.sun.tools.javac.api.BasicJavacTask.initPlugin(BasicJavacTask.java:255)
	at jdk.compiler/com.sun.tools.javac.api.BasicJavacTask.initPlugins(BasicJavacTask.java:229)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:292)
	at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
	at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
	at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

This does not occur when JDK 11 is used. The reason for that is that the additional configuration in jvm.config (as described here) was not taken into account.

So I finally got it working by defining the flags in the compilerArgs of the compiler plugin configuration:

<compilerArgs>
  <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
  <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
  <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
  <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
  <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
  <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
  <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
  <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
  <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
  <arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
  <arg>-XDcompilePolicy=simple</arg>
  <arg>-Xplugin:ErrorProne</arg>
</compilerArgs>

The --add-exports/--add-opens should be -J--add-exports/-J--add-opens here: https://errorprone.info/docs/installation#command-line