Description
Describe the Issue
Occurs in https://github.com/googleapis/google-http-java-client when running mvn test -Pnative
using GraalVM for JDK 24.0.1
You can find a partial non-minimal reproducer in googleapis/google-http-java-client#2101 - that helped me understand that there is something in the parent project causing this, maybe the execution profile or some dependency.
The following test case behaves differently in the JDK vs the native image.
@Test
public void testRepro() throws InstantiationException, IllegalAccessException {
System.out.println("Here, Object.class.getName() = " + Object.class.getName());
// class.getDeclaredConstructor().newInstance() behaves in the same way
String nullOfObject = Object.class.newInstance().getClass().getName();
System.out.println("The result of nullOf(Object.class).getClass().getName() = " + nullOfObject);
assertEquals("java.lang.Object", nullOfObject);
}
In the JDK, the stdout shows as:
Here, Object.class.getName() = java.lang.Object
The result of nullOf(Object.class).getClass().getName() = java.lang.Object
However, the native image uses a stub class for some reason.
Here, Object.class.getName() = java.lang.Object
The result of nullOf(Object.class).getClass().getName() = com.oracle.svm.core.reflect.serialize.SerializationSupport$StubForAbstractClass
com.google.api.client.util.DataTest > testRepro FAILED
Failures (1):
JUnit Vintage:DataTest:testRepro
MethodSource [className = 'com.google.api.client.util.DataTest', methodName = 'testRepro', methodParameterTypes = '']
=> org.junit.ComparisonFailure: expected:<[java.lang.Object]> but was:<[com.oracle.svm.core.reflect.serialize.SerializationSupport$StubForAbstractClass]>
In order to isolate this within google-http-java-client, I have tried removing all metadata files (i.e. rename x-config.json
to x-config.bak.json
inside META-INF/native-image/.../), effectively not having any special config affecting this.
I'm yet to exhaust other ideas to find out the root cause but I'd like to understand if there is a certain aspect of graalvm configs that could be influencing this in order to narrow this down a bit.
Thanks beforehand for the help!
Using the latest version of GraalVM can resolve many issues.
- I tried with the latest version of GraalVM.
GraalVM Version
$ java -version
openjdk version "24.0.1" 2025-04-15
OpenJDK Runtime Environment GraalVM CE 24.0.1+9.1 (build 24.0.1+9-jvmci-b01)
OpenJDK 64-Bit Server VM GraalVM CE 24.0.1+9.1 (build 24.0.1+9-jvmci-b01, mixed mode, sharing)
Operating System and Version
Occurs in CYGWIN 10.0 and Ubuntu 22
Troubleshooting Confirmation
- I tried the suggestions in the troubleshooting guide.
Run Command
mvn clean test -Pnative,native-tests,native-deps -Dagent=true -Dtest=com.google.api.client.util.DataTest#testRepro -T1.5C -pl 'google-http-client'
Expected Behavior
Object.class.newInstance()
returns a java.lang.Object
Actual Behavior
Object.class.newInstance()
returns com.oracle.svm.core.reflect.serialize.SerializationSupport$StubForAbstractClass
Steps to Reproduce
Occurs in https://github.com/googleapis/google-http-java-client when running mvn test -Pnative
using GraalVM for JDK 24.0.1
You can find a partial non-minimal reproducer in googleapis/google-http-java-client#2101 - that helped me understand that there is something in the parent project causing this, maybe the execution profile or some dependency.
Additional Context
No response
Run-Time Log Output and Error Messages
No response