JUnit execution fails with InaccessibleObjectException: Unable to make public void ...() accessible: module ... does not "exports ..." to unnamed module #2409
I am using the JPMS (Java Platform Module System) in my OSS project.
Now I stumbled over a bug in Eclipse preventing my JUnit test to work:
I do have an abstract base test class extended by multiple test cases that resides in a parent package that is empty in src/main/java and therefore cannot be exported in module-info.java
This abstract base class has a public @Test method doing some generic tests to be covered by all extended test cases.
When I run a concrete (non-abstract) JUnit test from a sub-package that extends the abstract base test class then Eclipse tries to run the public test method from that abstract base test class but fails to do so.
The error is that I get this unexpected stacktrace:
java.lang.reflect.InaccessibleObjectException: Unable to make public void io.github.mmm.entity.property.PropertyTest.testFactory() accessible: module io.github.mmm.entity.bean does not "exports io.github.mmm.entity.property" to unnamed module @4550bb58
at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:391)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:367)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:315)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:203)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:197)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Please note that mvn via maven-surefire-plugin does not cause this error and in the terminal, I can run my tests successfully with mvn test. As it seems mvn had the same bug but it has been fixed many years ago: https://issues.apache.org/jira/browse/SUREFIRE-1909
So maybe using add-opens could help to fix this.
Environment
Eclipse IDE for Java Developers (includes Incubating components)
Version: 2024-03 (4.31.0)
Build id: 20240307-1437
I can't find Eclipse project there. Many issues in JDT are related to the way how projects are setup. Please provide some simple self containing example that shows the issue, ideally as a zipped project.
Problem
I am using the JPMS (Java Platform Module System) in my OSS project. Now I stumbled over a bug in Eclipse preventing my JUnit test to work:
src/main/java
and therefore cannot be exported inmodule-info.java
@Test
method doing some generic tests to be covered by all extended test cases.The error is that I get this unexpected stacktrace:
Links
Hints
Please note that
mvn
viamaven-surefire-plugin
does not cause this error and in the terminal, I can run my tests successfully withmvn test
. As it seemsmvn
had the same bug but it has been fixed many years ago: https://issues.apache.org/jira/browse/SUREFIRE-1909So maybe using
add-opens
could help to fix this.Environment