serializer icon indicating copy to clipboard operation
serializer copied to clipboard

`InaccessibleObjectException` with `SetFromMap` in GraalVM Native Image Build

Open LiveNathan opened this issue 1 year ago • 3 comments

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:

  1. Add EclipseStore to a Spring Boot application.
  2. Build with GraalVM native-image.
  3. 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!

LiveNathan avatar Oct 28 '24 19:10 LiveNathan

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

danthe1st avatar Oct 28 '24 20:10 danthe1st

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).

fniephaus avatar Oct 29 '24 14:10 fniephaus

I noticed that the EclipseStore homepage shows a graalvm logo now. Does that mean that this issue has been resolved?

Image

LiveNathan avatar May 07 '25 20:05 LiveNathan