eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
165 stars 130 forks source link

JUnit execution fails with InaccessibleObjectException: Unable to make public void ...() accessible: module ... does not "exports ..." to unnamed module #2409

Closed hohwille closed 4 months ago

hohwille commented 6 months ago

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:

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)

image

Links

Hints

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
iloveeclipse commented 6 months ago

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.

jukzi commented 4 months ago

Closing due to missing information

hohwille commented 1 month ago

I can't find Eclipse project there. Many issues in JDT are related to the way how projects are setup.

For the record: All I do is "import as existing maven project". I also analyzed and described the problem in detail. Surely if Eclipse is drowning in issues, this is not high prio and can be ignored. I have a workaround by moving the abstract base test to a different package.