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

Since Jacoco 0.8.9, "--add-opens java.base/java.lang=ALL-UNNAMED" has no effect. #1487

Closed
zouyufei1989 opened this issue Jun 24, 2023 · 2 comments
Labels
declined: otherproject 👽 This issue should be reported to other project

Comments

@zouyufei1989
Copy link

zouyufei1989 commented Jun 24, 2023

Steps to reproduce

  • JaCoCo version: >=0.8.9
  • Operating system: Windows10
  • Tool integration: Idea
  • Complete executable reproducer:
    git repo: https://github.com/zouyufei1989/jacocoTest
  • Steps: (what exactly are you doing with the above reproducer?)
    run Jacoco089Test with VM options: '--add-opens java.base/java.lang=ALL-UNNAMED'

Expected behaviour

success as running org.example.Main
image

Actual behaviour

running test failed with VM options: '--add-opens java.base/java.lang=ALL-UNNAMED', which is different from running java program.

image

Unable to make final void java.lang.Throwable.setCause(java.lang.Throwable) accessible: module java.base does not "opens java.lang" to unnamed module @4d591d15
java.lang.reflect.InaccessibleObjectException: Unable to make final void java.lang.Throwable.setCause(java.lang.Throwable) accessible: module java.base does not "opens java.lang" to unnamed module @4d591d15
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
	at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
	at Jacoco089Test.test(Jacoco089Test.java:10)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at 
@zouyufei1989 zouyufei1989 added the type: bug 🐛 Something isn't working label Jun 24, 2023
@Godin
Copy link
Member

Godin commented Jun 24, 2023

After the removal of JaCoCo from build.gradle as following

 plugins {
     id 'java'
-    id 'jacoco'
 }

 ext {
@@ -11,7 +10,6 @@ ext {
     mockitoInlineVersion = "5.2.0"
     byteBuddyVersion = "1.14.5"
     junitPlatformVersion = "1.9.3"
-    jacocoVersion = "0.8.9"
     reflectionsVersion = "0.10.2"
 }

@@ -37,11 +35,6 @@ dependencies {

 }

-jacoco {
-    toolVersion = "${jacocoVersion}"
-    reportsDirectory = layout.buildDirectory.dir("jacoco")
-}
-
 test {
     useJUnitPlatform()
 }

i.e. for the following build.gradle

plugins {
    id 'java'
}

ext {
    xmlApisVersion = "2.0.2"
    assertJVersion = "3.24.2"
    jUnit5Version = "5.9.3"
    mockitoVersion = "5.4.0"
    mockitoInlineVersion = "5.2.0"
    byteBuddyVersion = "1.14.5"
    junitPlatformVersion = "1.9.3"
    reflectionsVersion = "0.10.2"
}


group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.mockito:mockito-core:${mockitoVersion}"
    implementation "org.mockito:mockito-junit-jupiter:${mockitoVersion}"
    implementation "org.mockito:mockito-inline:${mockitoInlineVersion}"
    implementation "org.junit.jupiter:junit-jupiter-api:${jUnit5Version}"
    implementation "org.junit.jupiter:junit-jupiter-params:${jUnit5Version}"
    implementation "org.junit.jupiter:junit-jupiter-engine:${jUnit5Version}"
    implementation "org.junit.vintage:junit-vintage-engine:${jUnit5Version}"
    implementation "org.junit.platform:junit-platform-launcher:${junitPlatformVersion}"
    implementation "org.junit.platform:junit-platform-engine:${junitPlatformVersion}"
    implementation "org.junit.platform:junit-platform-commons:${junitPlatformVersion}"

}

test {
    useJUnitPlatform()
}

execution of test with following configuration

Screenshot 2023-06-24 at 07 24 51

anyway fails with the same exception

java.lang.reflect.InaccessibleObjectException: Unable to make final void java.lang.Throwable.setCause(java.lang.Throwable) accessible: module java.base does not "opens java.lang" to unnamed module @1a27aae3

because the specification of VM Options in the above configuration does not affect JVM that executes test as can be seen in debug output

2023-06-24T07:29:02.715+0200 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'Gradle Test Executor 12'. Working directory: /private/tmp/jacocoTest Command: /Users/godin/.java-select/versions/openjdk-17/bin/java -Dorg.gradle.internal.worker.tmpdir=/private/tmp/jacocoTest/build/tmp/test/work -Dorg.gradle.native=false -javaagent:build/tmp/expandedArchives/org.jacoco.agent-0.8.9.jar_0bd0851504e6286cb5fc6f37a81e25cc/jacocoagent.jar=destfile=build/jacoco/test.exec,append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false @/Users/godin/.gradle/.tmp/gradle-worker-classpath8877070980104096582txt -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 12'

I do not know whether this is due to a bug in IntelliJ IDEA or somewhere else, but clearly not in JaCoCo.

With JaCoCo versions 0.8.3 - 0.8.8 you might think that the above specification of VM Options has effect, because JaCoCo itself was erroneously opening java.lang package to the unnamed module of the application class loader, which was fixed in JaCoCo 0.8.9 - #1334

The test passes with and without JaCoCo 0.8.9 when --add-opens java.base/java.lang=ALL-UNNAMED specified in build.gradle as following

test {
    useJUnitPlatform()
    jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED"]
}

and in this case debug output shows that option is passed to JVM that executes test

2023-06-24T07:39:34.874+0200 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'Gradle Test Executor 16'. Working directory: /private/tmp/jacocoTest Command: /Users/godin/.java-select/versions/openjdk-17/bin/java -Dorg.gradle.internal.worker.tmpdir=/private/tmp/jacocoTest/build/tmp/test/work -Dorg.gradle.native=false --add-opens java.base/java.lang=ALL-UNNAMED @/Users/godin/.gradle/.tmp/gradle-worker-classpath13265874780622735957txt -Xmx512m -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 16'

@Godin Godin closed this as completed Jun 24, 2023
@Godin Godin added declined: otherproject 👽 This issue should be reported to other project and removed type: bug 🐛 Something isn't working labels Jun 24, 2023
@zouyufei1989
Copy link
Author

Hello @Godin It now works, so thank you very much! And I appreciate how you handled the triage, which is a really fantastic example for us to follow as we try to solve other similar problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
declined: otherproject 👽 This issue should be reported to other project
Projects
None yet
Development

No branches or pull requests

2 participants