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

Access to compiler internal APIs will fail starting with JDK 16 #222

Open
eamonnmcmanus opened this issue Mar 11, 2021 · 7 comments
Open
Labels
P3 type=defect Bug, not working as expected

Comments

@eamonnmcmanus
Copy link
Member

JDK 16 will change the default for the --illegal-access flag from permit to deny. This means that, by default, compile-testing tests will fail with messages like this:

class com.google.testing.compile.Parser (in unnamed module @0x4114d843) cannot access class
com.sun.tools.javac.api.JavacTool (in module jdk.compiler) because module jdk.compiler does not export
com.sun.tools.javac.api to unnamed module @0x4114d843

That can be worked around either by explicitly specifying, on the command line of the JVM running the tests, either --illegal-access=permit or --add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED. We should document that, and perhaps later find a way to make it unnecessary.

copybara-service bot pushed a commit to google/auto that referenced this issue Mar 11, 2021
As noted [here](google/compile-testing#222), the change of the default `--illegal-access` from `permit` to `deny` will cause compile-testing tests to fail by default, with messages like this:

```
class com.google.testing.compile.Parser (in unnamed module @0x4114d843) cannot
access class
com.sun.tools.javac.api.JavacTool (in module jdk.compiler) because module
jdk.compiler does not export
com.sun.tools.javac.api to unnamed module @0x4114d843
```

We can work around that by supplying the necessary `--add-opens` flag to the JVM that runs the tests.

RELNOTES=n/a
PiperOrigin-RevId: 362396186
copybara-service bot pushed a commit to google/auto that referenced this issue Mar 12, 2021
As noted [here](google/compile-testing#222), the change of the default `--illegal-access` from `permit` to `deny` will cause compile-testing tests to fail by default, with messages like this:

```
class com.google.testing.compile.Parser (in unnamed module @0x4114d843) cannot
access class com.sun.tools.javac.api.JavacTool (in module jdk.compiler) because
module jdk.compiler does not export com.sun.tools.javac.api to unnamed module
@0x4114d843
```

We can work around that by supplying the necessary `--add-opens` flag to the JVM that runs the tests.

RELNOTES=n/a
PiperOrigin-RevId: 362396186
copybara-service bot pushed a commit to google/auto that referenced this issue Mar 12, 2021
As noted [here](google/compile-testing#222), the change of the default `--illegal-access` from `permit` to `deny` will cause compile-testing tests to fail by default, with messages like this:

```
class com.google.testing.compile.Parser (in unnamed module @0x4114d843) cannot
access class com.sun.tools.javac.api.JavacTool (in module jdk.compiler) because
module jdk.compiler does not export com.sun.tools.javac.api to unnamed module
@0x4114d843
```

We can work around that by supplying the necessary `--add-opens` flag to the JVM that runs the tests.

RELNOTES=n/a
PiperOrigin-RevId: 362531170
@cgdecker cgdecker added P3 type=defect Bug, not working as expected labels Mar 12, 2021
remkop added a commit to remkop/picocli that referenced this issue Mar 31, 2021
@ZacSweers
Copy link
Contributor

Just mentioning that the --illegal-access flag was removed in JDK 17, so any solution for this would likely need to use --add-opens

MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…ompiler internal APIs on Java 16"

This reverts commit 008a719.
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
…ompiler internal APIs on Java 16"

This reverts commit 008a719.
@h908714124
Copy link

h908714124 commented Nov 6, 2021

Consider deprecating methods containsElementsIn and hasSourceEquivalentTo in class JavaFileObjectSubject. These use Parser internally, which depends on forbidden Sun APIs. With some effort, it should be possible to rewrite affected tests and use method generatedSourceFile in class Compilation instead. This is the future-proof way to compare the generated source with expectations. See this commit for example.

@almogtavor
Copy link

@h908714124 is right, but as a workaround:

test {
    jvmArgs "--add-opens=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"
    useJUnitPlatform()
}

would work

mikewacker added a commit to mikewacker/annotation-processor-example that referenced this issue May 8, 2023
Additional `--add-exports` JVM args were needed for testing.

See: google/compile-testing#222
@mikewacker
Copy link

@almogtavor Here's an updated workaround for Gradle:

test {
    useJUnitPlatform()

    // See: https://github.com/google/compile-testing/issues/222
    jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED'
    jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED'
    jvmArgs '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED'
}

Notes:

  • You only need to use --add-exports, --add-opens is overkill.
  • As of release 0.20, two additional --add-exports are needed. See: cd2c0a8

@xenoterracide
Copy link

looks like I just hit this

    java.lang.IllegalAccessError: class com.google.testing.compile.Parser (in unnamed module @0x15bbf42f) 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 @0x15bbf42f
        at com.google.testing.compile.Parser.parse(Parser.java:63)
        at com.google.testing.compile.JavaFileObjectSubject.performTreeDifference(JavaFileObjectSubject.java:173)
        at com.google.testing.compile.JavaFileObjectSubject.hasSourceEquivalentTo(JavaFileObjectSubject.java:126)
        at com.xenoterracide.bygger.ClassAnnotationTest.testImmutable(ClassAnnotationTest.java:53)

@xenoterracide
Copy link

Here's the kotlin dsl (which is now the default) equivalent of the above

tasks.test.configure {
  useJUnitPlatform()

  // See: https://github.com/google/compile-testing/issues/222
  jvmArgs =listOf(
    "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
    "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
    "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
  )

@ChristophLoy
Copy link

ChristophLoy commented Aug 8, 2023

Here's the kotlin dsl (which is now the default) equivalent of the above

tasks.test.configure {
  useJUnitPlatform()

  // See: https://github.com/google/compile-testing/issues/222
  jvmArgs =listOf(
    "--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
    "--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
    "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
  )

@xenoterracide This is not the same! By assigning the jvmArgs via the = operator, you remove all existing jvmArgs. The actual equivalent would be:

    jvmArgs("--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED")
    jvmArgs("--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED")
    jvmArgs("--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED")

aurambaj added a commit to pinterest/l10nmessages that referenced this issue Nov 14, 2023
When trying to run the test with Java 17, there was an issue with assertion accessing internal API. As reported in: google/compile-testing#222.

As a fix, replaced asserts with plain text asserts, inspired by google/auto#1004

To be running the test on Java 17. Need to update the processor test to
aurambaj added a commit to pinterest/l10nmessages that referenced this issue Nov 15, 2023
When trying to run the test with Java 17, there was an issue with assertion accessing internal API. As reported in: google/compile-testing#222.

As a fix, replaced asserts with plain text asserts, inspired by google/auto#1004

To be running the test on Java 17. Need to update the processor test to
copybara-service bot pushed a commit that referenced this issue Dec 20, 2023
The `--add-exports=` flags are required after https://openjdk.org/jeps/396

Related to #222

RELNOTES=n/a
PiperOrigin-RevId: 592669579
copybara-service bot pushed a commit that referenced this issue Dec 20, 2023
The `--add-exports=` flags are required after https://openjdk.org/jeps/396

Related to #222

RELNOTES=n/a
PiperOrigin-RevId: 592675658
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 type=defect Bug, not working as expected
Projects
None yet
Development

No branches or pull requests

8 participants