Skip to content

picocli-annotation-processing-tests fail on Java 16+ #1939

@remkop

Description

@remkop

Related to #1930

Annotation tests fail on Java 16+ with this error:

java.lang.IllegalAccessError: class com.google.testing.compile.Parser (in unnamed module @0xc267ef4) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module

The build.gradle for that module had the below workaround for this, but this no longer seems to work...

tasks.withType(Test.class) {
    if (org.gradle.api.JavaVersion.current().isJava12Compatible()) { // only a problem from Java 16, but okay
        // https://github.com/google/compile-testing/issues/222
        it.jvmArgs '--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' 
    }
}

google/compile-testing#222 (comment) suggests fixing the tests to avoid some methods and do String comparison instead of relying on functionality that depends on the internal compiler.

E.g. in java/picocli/annotation/processing/tests/Issue769Test.java, the following change fixes the issue:

//        assertThat(compilation)
//                .generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/MyMixin.java")
//                .hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/issue769/MyMixin.java"));

        String generated1 = compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/MyMixin.java").get().getCharContent(false).toString();
        String expected1 = JavaFileObjects.forResource("generated/picocli/issue769/MyMixin.java").getCharContent(false).toString();
        assertEquals(expected1.replaceAll("\\r?\\n", "\n"), generated1.replaceAll("\\r?\\n", "\n"));


//        assertThat(compilation)
//                .generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/SubCommand.java")
//                .hasSourceEquivalentTo(JavaFileObjects.forResource("generated/picocli/issue769/SubCommand.java"));
        String generatedSub = compilation.generatedFile(StandardLocation.SOURCE_OUTPUT, "generated/picocli/issue769/SubCommand.java").get().getCharContent(false).toString();
        String expectedSub = JavaFileObjects.forResource("generated/picocli/issue769/SubCommand.java").getCharContent(false).toString();
        assertEquals(expectedSub.replaceAll("\\r?\\n", "\n"), generatedSub.replaceAll("\\r?\\n", "\n"));

Metadata

Metadata

Assignees

No one assigned

    Labels

    javaPull requests that update Java codetheme: buildAn issue or change related to the build systemtype: bug 🐛

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions