Skip to content

InaccessibleObjectException is not thrown by gradle #18671

@sukolenvo

Description

@sukolenvo

gradle test passes successfully in CI but fails in production with java.lang.reflect.InaccessibleObjectException, i.e. tests pass when executed by gradle by fails when executed with java -cp ....

I can see in logs that multiple --add-open are used in gradle daemon:

2021-10-16T12:54:17.238+0800 [DEBUG] [org.gradle.launcher.daemon.server.exec.ExecuteBuild] Executing build with daemon context: DefaultDaemonContext[uid=17080b27-1ebe-47be-b046-fd5766bfbfab,javaHome=/home/gtx/.jdks/semeru-jdk-17+35,daemonRegistryDir=/home/gtx/.gradle/daemon,pid=21961,idleTimeout=10800000,priority=NORMAL,
daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.base/java.lang=ALL-UNNAMED,--add-opens,java.base/java.lang.invoke=ALL-UNNAMED,--add-opens,java.base/java.util=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens,java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens,java.base/java.nio.charset=ALL-UNNAMED,--add-opens,java.base/java.net=ALL-UNNAMED,--add-opens,java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xms256m,-Xmx512m,-Dfile.encoding=UTF-8,-Duser.country=AU,-Duser.language=en,-Duser.variant]

Likely by following class: https://github.com/gradle/gradle/blob/4a482a4c36576fafe8398e4717bd779f7f76a3e5/subprojects/base-services/src/main/java/org/gradle/internal/jvm/JpmsConfiguration.java

Expected Behavior

Expecting tests to fail with same error as production code.

Current Behavior

Test passes successfully.

Context

I would like to rely on tests and CI to catch runtime exceptions. I was also able to reproduce same issue with java 16, but not as reliable (some toolchains pass, some fail without clear difference). Is there a way to isolate from gradle daemon environment?

Steps to Reproduce

Sample project: https://github.com/sukolenvo/sample-gradle-java-17
./gradlew test

Your Environment

I don't think there is something specific to my environment, nevertheless build scan attached.
Build scan URL: https://scans.gradle.com/s/hst2fqczytf4u

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions