`InaccessibleObjectException` with `SetFromMap` in GraalVM Native Image Build
https://github.com/eclipse-serializer/serializer/blob/6dbcfc87c3ed899401e475c1a432ff3bad82ed5f/persistence/binary/src/main/java/org/eclipse/serializer/persistence/binary/java/util/BinaryHandlerSetFromMap.java#L39
Description:
While building a native image of a Spring Boot application using GraalVM (v21.0.5, Java 21) and EclipseStore (v2.0.0), I encountered the following error due to SetFromMap:
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field final java.util.Map java.util.Collections$SetFromMap.m accessible...
I've attempted multiple configurations (reflect-config.json, --add-opens, RuntimeHints) without success. A community suggestion pointed out that Eclipse Serializer might rely on reflective access to internal Java classes. Could Serializer adapt to avoid internal class access to ensure compatibility with GraalVM native images?
Steps to Reproduce:
- Add EclipseStore to a Spring Boot application.
- Build with GraalVM native-image.
- Run the native image.
Expected Behavior: No reflection errors in GraalVM native image builds.
Additional Information:
GitHub Repository: LiveNathan/nativeImageTest Stackoverflow Question: GraalVM native image build fails using EclipseStore EclipseStore Discussion: Eclipse Store GitHub Discussion #297
Thank you!
Note that Eclipse Serializer doesn't only reflectively access Collections$SetFromMap.m (which requires --add-opens java.base/java.util=org.eclipse.serializer) but also many other classes in the org.eclipse.serializer and org.eclipse.store packages.
The following types can be found when running the test in @LiveNathan's reproducer and removing everything that isn't Eclipse Serializer/Eclipse Store (I think the dependencies for Eclipse Store are specific to how Eclipse Store uses Eclipse Serializer): reflect-config.json
Thanks for filing this, @LiveNathan. Would be great if the eclipse-serializer project could look into proper Native Image support. If any help is needed, we are happy to help (I work on the GraalVM team).
I noticed that the EclipseStore homepage shows a graalvm logo now. Does that mean that this issue has been resolved?