Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
remkop opened this issue Jan 26, 2023 · 0 comments
Closed

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

remkop opened this issue Jan 26, 2023 · 0 comments
Labels
java Pull requests that update Java code theme: build An issue or change related to the build system type: bug 🐛
Milestone

Comments

@remkop
Copy link
Owner

remkop commented Jan 26, 2023

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"));
@remkop remkop added type: bug 🐛 theme: build An issue or change related to the build system java Pull requests that update Java code labels Jan 26, 2023
@remkop remkop added this to the 4.7.1 milestone Jan 26, 2023
@remkop remkop closed this as completed in 2c1a60c Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java Pull requests that update Java code theme: build An issue or change related to the build system type: bug 🐛
Projects
None yet
Development

No branches or pull requests

1 participant