You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to deserialize an XML representation of a Java Bean using java.beans.XMLDecoder, the native image fails with an ArrayIndexOutOfBoundsException.
The same code works well when packaged as a runnable Jar. However, it fails when run as a native image. I have also tried to include the bean class (test.Person) in reflect-config and also serialization-config hints.
Using the latest version of GraalVM can resolve many issues.
Person object is constructed successfully and the below string is printed
Hello from Person{firstName='John', lastName='Doe', age=50}
Actual Behavior
Running the native App results in error as below
java.lang.InstantiationException: com.sun.beans.decoder.JavaElementHandler
Continuing ...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.desktop@21/java.beans.XMLDecoder.readObject(XMLDecoder.java:253)
at test.XmlDecoderTest.decodeTestPerson(XmlDecoderTest.java:13)
at test.XmlDecoderTest.main(XmlDecoderTest.java:8)
at java.base@21/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
java.lang.InstantiationException: com.sun.beans.decoder.JavaElementHandler
Continuing ...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.desktop@21/java.beans.XMLDecoder.readObject(XMLDecoder.java:253)
at test.XmlDecoderTest.decodeTestPerson(XmlDecoderTest.java:13)
at test.XmlDecoderTest.main(XmlDecoderTest.java:8)
at java.base@21/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
The text was updated successfully, but these errors were encountered:
I can confirm that the behavior is the same with Oracle GraalVM 23+37.1 (build 23+37-jvmci-b01). It still shows the below error when run as a native image whereas it works just fine as a jar.
java.lang.InstantiationException: com.sun.beans.decoder.JavaElementHandler
Continuing ...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.desktop@23/java.beans.XMLDecoder.readObject(XMLDecoder.java:253)
at test.XmlDecoderTest.decodeTestPerson(XmlDecoderTest.java:13)
at test.XmlDecoderTest.main(XmlDecoderTest.java:8)
at java.base@23/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
thanks for reporting this, and especially for the simple reproducer with step-by-step instructions, that makes it super easy to exactly reproduce your problem.
So after building the class files, run the application once (in JIT mode) and add -agentlib:native-image-agent=config-output-dir=..... Output to e.g. build/META-INF/native-image/. Then build the JAR file with those files included, and native-image will use the configuration information to build the image.
App.jar roughly doubled in size for me, App (executable) got slightly bigger (+400k), but now it works:
$ ./App
Hello from Person{firstName='John', lastName='Doe', age=50}
I think we need to add that information to the Troubleshooting guide.
Describe the Issue
When trying to deserialize an XML representation of a Java Bean using
java.beans.XMLDecoder
, the native image fails with anArrayIndexOutOfBoundsException
.The same code works well when packaged as a runnable Jar. However, it fails when run as a native image. I have also tried to include the bean class (
test.Person
) inreflect-config
and alsoserialization-config
hints.Using the latest version of GraalVM can resolve many issues.
GraalVM Version
Oracle GraalVM 21+35.1 (build 21+35-jvmci-23.1-b15)
Operating System and Version
Darwin Kernel Version 23.0.0
Troubleshooting Confirmation
Run Command
./App
Expected Behavior
Person object is constructed successfully and the below string is printed
Actual Behavior
Running the native App results in error as below
Steps to Reproduce
XmlDecoderTest.java
Person.java
** Build **
javac -d build test/XmlDecoderTest.java
jar --create --file App.jar --main-class test.XmlDecoderTest -C build .
native-image -jar App.jar
** Test jar **
java -jar App.jar
** Test native-image **
./App
Additional Context
No response
Run-Time Log Output and Error Messages
java.lang.InstantiationException: com.sun.beans.decoder.JavaElementHandler
Continuing ...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.desktop@21/java.beans.XMLDecoder.readObject(XMLDecoder.java:253)
at test.XmlDecoderTest.decodeTestPerson(XmlDecoderTest.java:13)
at test.XmlDecoderTest.main(XmlDecoderTest.java:8)
at java.base@21/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
The text was updated successfully, but these errors were encountered: