Skip to content

[GR-66194] java.lang.Object.newInstance() returns instance of SerializationSupport$StubForAbstractClass #11429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks
diegomarquezp opened this issue Jun 17, 2025 · 1 comment
Assignees

Comments

@diegomarquezp
Copy link

diegomarquezp commented Jun 17, 2025

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.

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

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

@fniephaus fniephaus changed the title [Native Image] java.lang.Object.newInstance() returns instance of SerializationSupport$StubForAbstractClass [GR-66194] java.lang.Object.newInstance() returns instance of SerializationSupport$StubForAbstractClass Jun 18, 2025
@fniephaus
Copy link
Member

Thanks a lot for the report, @diegomarquezp! This definitely looks like a bug that we need to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants