javamavenchecker-framework

Exception running Maven compiler plugin (3.11.0) with checker framework


I have a Maven project. I can compile it successfully with

<fork>false</false> <!-- this is the default setting of fork. see: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#fork -->
<compilerArgs combine.children="append">
                    <arg>--enable-preview</arg>
                    <arg>--add-modules</arg>
                    <arg>jdk.incubator.vector</arg>                    

However I am trying to use the checker framework and it requires setting fork to true. [1]. But as soon as I try to do this:

<fork>true</false> 
<compilerArgs combine.children="append">
                    <arg>--enable-preview</arg>
                    <arg>--add-modules</arg>
                    <arg>jdk.incubator.vector</arg>                    

I now get an error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project xxx-utils: Compilation failure: Compilation failure:
[ERROR] using incubating module(s): jdk.incubator.vector
[ERROR] using incubating module(s): jdk.incubator.vector
[ERROR] using incubating module(s): jdk.incubator.vector

Maven callstack:

Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1214)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:193)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)

Line that is causing the exception [2]:

throw new CompilationFailureException(warnings);

command-line options Maven is passing to javac:

[DEBUG] Excutable:
[DEBUG]  /Library/Java/jdk-21.0.1.jdk/Contents/Home/bin/javac
[DEBUG] Command line options:
[DEBUG] -d /Users/xxx/code/xxx/utils/target/classes -classpath ... -sourcepath ... -s /Users/xxx/code/xxx/utils/target/generated-sources/annotations -processor org.checkerframework.checker.nullness.NullnessChecker -processorpath ... -g -parameters --release 21 -encoding UTF-8 -Xmaxerrs 10000 -Xmaxwarns 10000 -Awarns --enable-preview --add-modules jdk.incubator.vector

Why is it an error all of a sudden to use an incubating module? It seems to be that compiler warnings seem to be manifesting as error. How can I fix this?

EDIT: The problem is not with Maven but with Checker Framework. If I remove the checker framework from the build config, it passes without any errors. Still looking for solution though. This is my config:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>      
                <jdkToolchain>
                    <version>21</version>
                </jdkToolchain>
                <fork>true</fork>                 
              <annotationProcessorPaths>
                <path>
                  <groupId>org.checkerframework</groupId>
                  <artifactId>checker</artifactId>
                  <version>3.42.0</version>
                </path>
              </annotationProcessorPaths>
              <annotationProcessors>
                <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
              </annotationProcessors>                 
                <compilerArgs combine.children="append">
                    <arg>-Xmaxerrs</arg>
                    <arg>10000</arg>
                    <arg>-Xmaxwarns</arg>
                    <arg>10000</arg>                                
                    <arg>-Awarns</arg>
                    <arg>--enable-preview</arg>
                    <arg>--add-modules</arg>
                    <arg>jdk.incubator.vector</arg>                    
                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
                    <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.code=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.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.comp=ALL-UNNAMED</arg>                    
              </compilerArgs>
            <parameters>true</parameters>          
                    </configuration>                
            </plugin>

Solution

  • Fixed it. The problem here was that I did not add the CF dependency to pom.xml [1]. :

    <dependency>
          <groupId>org.checkerframework</groupId>
          <artifactId>checker-qual</artifactId>
          <version>3.42.0</version>
        </dependency>
    

    there was a reason for this as I was not actually using CF in the source code but I guess that does not matter whether you use it or not, you still need to add the dependency for the annotation processor to work as the processor relies on the classpath to pick up the library.

    Ultimately maven gets the blame for not reporting the actual error in the console. Looks like this bug is still not fixed in maven.