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

TestKit is broken when tests execute Java compilation and debugging is turned on #29696

Open
hegyibalint opened this issue Jun 26, 2024 · 0 comments · May be fixed by #29684
Open

TestKit is broken when tests execute Java compilation and debugging is turned on #29696

hegyibalint opened this issue Jun 26, 2024 · 0 comments · May be fixed by #29684
Assignees
Milestone

Comments

@hegyibalint
Copy link
Member

Current behavior

When:

  • TestKit is used to execute a build
  • The build does something related to a Java compilation
  • And the executor is used with debugging on

The test will fail with an IllegalAccessError:

Caused by: java.lang.IllegalAccessError: class org.gradle.api.internal.tasks.compile.JdkJavaCompiler (in unnamed module @0x25377fa1) 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 @0x25377fa1	
	at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.<init>(JdkJavaCompiler.java:59)	
	at org.gradle.api.internal.tasks.compile.DefaultJavaCompilerFactory.createTargetCompiler(DefaultJavaCompilerFactory.java:93)

Expected Behavior

TestKit-driven tests should not fail when debugging is on.

Context

The modifications done in order to extract more structured compiler information (#28281) made it necessary to have new --add-exports flags:

"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", // Required by JdkTools and JdkJavaCompiler
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" // Required by JdkTools and JdkJavaCompiler

The modification above made sure that normally executed builds were executed with the correct flags.
We've made a mistake and not expanded the list of JVM flags passed to the test executor set by java-gradle-plugin.

This made the behavior differ:

  • When debugging is off, the Gradle runner is forked, and our standard mechanism adds the flags to the forked java process.
  • When debugging is on, the Gradle runner is embedded inside the test JVM (i.e. no forking happens), and this necessitates that you already have a JVM with the correct flags applied; otherwise, the IllegalAccessError presented above will happen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant