To Reproduce
Uncompress the attached maven project and run mvn -Pnative package.
Expected behavior
The tests from the attached project should also pass in native mode. Currently, they are failing.
Logs
See comments in the src/test/java/org/me/MainTest.java
System Info:
OS: macos
GraalVM Version 23.1.2
Java Version 21
Plugin version native-maven-plugin:0.10.0
Additional context
The issue arises from org.hamcrest.TypeSafeMatcher and org.hamcrest.TypeSafeDiagnosingMatcher utilizing ReflectiveTypeFinder to locate the matchesSafely method in their subclasses during image execution. This problem can be resolved by employing a reflection configuration file. Although the reflection.json file is included in the test project, it is commented out in the pom.xml. Since the reflective access targets JUnit types, it should ideally be handled by the JUnitPlatformFeature rather than by the application itself.
One approach is to eliminate type safety, similar to what is implemented in the internal GraalVM JUnit support. However, this method requires a substitution, which is not a public API.
Alternatively, we can register all used subclasses of TypeSafeMatcher and TypeSafeDiagnosingMatcher for reflective access to all declared methods. Implemented here.
Describe the bug The native junit test fails if the
org.junit.rules.ExpectedException
ororg.hamcrest.core.Every
is used by the test.To Reproduce Uncompress the attached maven project and run
mvn -Pnative package
.Expected behavior The tests from the attached project should also pass in native mode. Currently, they are failing.
Logs See comments in the
src/test/java/org/me/MainTest.java
System Info:
native-maven-plugin:0.10.0
Additional context The issue arises from
org.hamcrest.TypeSafeMatcher
andorg.hamcrest.TypeSafeDiagnosingMatcher
utilizingReflectiveTypeFinder
to locate thematchesSafely
method in their subclasses during image execution. This problem can be resolved by employing a reflection configuration file. Although thereflection.json
file is included in the test project, it is commented out in thepom.xml
. Since the reflective access targets JUnit types, it should ideally be handled by theJUnitPlatformFeature
rather than by the application itself.One approach is to eliminate type safety, similar to what is implemented in the internal GraalVM JUnit support. However, this method requires a substitution, which is not a public API.
Alternatively, we can register all used subclasses of
TypeSafeMatcher
andTypeSafeDiagnosingMatcher
for reflective access to all declared methods. Implemented here.