javachecker-framework

Checker Framework Build Error - fromClass can't load class org.checkerframework.dataflow.qual.Deterministic


I am trying to integrate checker framework to my maven project which runs on Java 17. I am following the guidelines here for the task.

https://checkerframework.org/manual/#maven

When I build the project I get the below error.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project combinecheckerror: Compilation failure
[ERROR] java.lang.NoSuchMethodError: 'int org.checkerframework.org.plumelib.util.CollectionsPlume.mapCapacity(int)'
[ERROR]         at org.checkerframework.common.basetype.BaseTypeChecker.getImmediateSubcheckerClasses(BaseTypeChecker.java:207)
[ERROR]         at org.checkerframework.checker.nullness.NullnessChecker.getImmediateSubcheckerClasses(NullnessChecker.java:79)
[ERROR]         at org.checkerframework.common.basetype.BaseTypeChecker.instantiateSubcheckers(BaseTypeChecker.java:454)
[ERROR]         at org.checkerframework.common.basetype.BaseTypeChecker.getSubcheckers(BaseTypeChecker.java:506)
[ERROR]         at org.checkerframework.common.basetype.BaseTypeChecker.getOptions(BaseTypeChecker.java:847)
[ERROR]         at org.checkerframework.framework.source.SourceChecker.hasOption(SourceChecker.java:1739)
[ERROR]         at org.checkerframework.framework.source.SourceChecker.init(SourceChecker.java:582)
[ERROR]         at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:701)
[ERROR]         at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:828)
[ERROR]         at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:924)
[ERROR]         at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1267)
[ERROR]         at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1382)
[ERROR]         at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1234)
[ERROR]         at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:916)
[ERROR]         at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:317)
[ERROR]         at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:176)
[ERROR]         at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:64)
[ERROR]         at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:50)

I have tried numerous guidelines apart from the official documentation to make this work but with no luck. Appreciate if someone can point out what I am doing wrong here. Below is my pom file. Thanks in advance.


<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.9</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.checkinganderror</groupId>
    <artifactId>combinecheckerror</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>combinecheckerror</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
        <revision>0.0.1-SNAPSHOT</revision>
        <error-prone.version>2.4.0</error-prone.version>
        <nullaway.version>0.9.9</nullaway.version>
        <maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
        <maven-enforcer-plugin.version>3.1.0</maven-enforcer-plugin.version>
        <spring-boot.version>2.7.3</spring-boot.version>
        <checker.framework.version>3.32.0</checker.framework.version>
        <errorProneJavac>${com.google.errorprone:javac:jar}</errorProneJavac>
        <jmh.version>1.35</jmh.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker</artifactId>
            <version>${checker.framework.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.checkerframework</groupId>
            <artifactId>checker-qual</artifactId>
            <version>${checker.framework.version}</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>checkerframework</id>
            <activation>
                <jdk>[9,)</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <fork>true</fork>
                            <compilerArguments>
                                <Xmaxerrs>10000</Xmaxerrs>
                                <Xmaxwarns>10000</Xmaxwarns>
                            </compilerArguments>
                            <compilerArgs combine.children="append">
                                <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>
                                <arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
                                <arg>-XDcompilePolicy=simple</arg>
                                <arg>-Xplugin:ErrorProne -Xep:HidingField:OFF -XepDisableWarningsInGeneratedCode -XepExcludedPaths:.*/src/test/java/.*|.*/generated-test-sources/.* / -XepOpt:NullAway:TreatGeneratedAsUnannotated=true -Xep:SameNameButDifferent:OFF -Xep:JavaLangClash:OFF -Xep:ObjectToString:OFF -Xep:AlmostJavadoc:OFF -Xep:ImmutableEnumChecker:OFF -Xep:SynchronizeOnNonFinalField:OFF
                                </arg>
                            </compilerArgs>

                        <annotationProcessorPaths>
                        <path>
                            <groupId>com.google.errorprone</groupId>
                            <artifactId>error_prone_core</artifactId>
                            <version>${error-prone.version}</version>
                        </path>
                            <path>
                                <groupId>org.checkerframework</groupId>
                                <artifactId>checker</artifactId>
                                <version>${checker.framework.version}</version>
                            </path>
                        </annotationProcessorPaths>
                            <annotationProcessors>
                                <!-- Add all the checkers you want to enable here -->
                                <annotationProcessor>org.checkerframework.checker.nullness.NullnessChecker</annotationProcessor>
                            </annotationProcessors>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <!-- Needed for animal-sniffer-maven-plugin version 1.19 (version 1.20 is fixed). -->
                <animal.sniffer.skip>true</animal.sniffer.skip>
            </properties>
        </profile>
    </profiles>

    <build>
        <pluginManagement>
            <plugins>
                <!-- Provides integration between Spring Boot and Maven.
                Should be included only in application modules, but not in library modules-->
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring-boot.version}</version>
                </plugin>
                <!-- Maven compiler plugin to enforce Java version and enable annotation processors -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                </plugin>
                <!-- Maven Enforcer to enforce various rules -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>${maven-enforcer-plugin.version}</version>
                </plugin>
                <!-- Spotless code formatter -->
                <plugin>
                    <groupId>com.diffplug.spotless</groupId>
                    <artifactId>spotless-maven-plugin</artifactId>
                    <version>${spotless.version}</version>
                </plugin>
                <!-- JaCoCo Code Coverage -->
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                </plugin>
                <plugin>
                    <!-- This plugin will set properties values using dependency information -->
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>properties</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Guides in the internet like these.

https://i-boy.hatenablog.com/entry/2016/06/02/225613 https://www.baeldung.com/checker-framework

I want to build the project successfully.


Solution

  • I don't know what your problem is, but I can suggest some ways to help diagnose it.

    It would be helpful to create a reproducible example that others can run, rather than providing a partial pom.xml file. For example, the partial pom.xml you provided gives no definition for maven-compiler-plugin.version; what version are you using? We also don't know the value of java.version which may be relevant. Without being able to run your example, others can only guess about what the problem is and what solutions might fix it.

    One problem is that lines 31 and 37 specify version 3.22.1, but line 144 specifies version 3.32.0. These versions must all be consistent.

    This is a long shot, but you could try adding a use of the checker-qual artifact around line 145 in addition to the use of the checker artifact there.

    Have you tried temporarily disabling the other annotation processors and just running the Checker Framework, to better investigate what the problem may be? (This would be part of creating a minimal, reproducible example.) For example, as mentioned in the manual (here, here), Lombok is invasive and can interfere with other annotation processors. I wouldn't expect this to cause the problem you are seeing, but you never know, so ruling this out would be useful.

    The Checker Framework Manual states that your pom.xml should contain several profiles, but yours does not. This is not necessarily a problem, but it makes it harder to diff your buildfile and the text in the manual to find differences. For example, the manual says to update not the <dependencies> section within <dependencyManagement> (as your pom.xml file does), but a different <dependencies> section in your pom.xml file.