Skip to content

Commit a855eca

Browse files
fix: add special handling for Object in Types.newInstance() (#2102)
https://togithub.com/oracle/graal/issues/11429 confirms a behavior problem when calling `Object.class.newInstance()`. This is a temporary workaround while the GraalVM team looks into this. Since `Types` relies on `Class.newInstance()`, we add a concrete case for `java.lang.Object.class` to avoid the mysterious `SerializationSupport$StubForAbstractClass` that comes instead of `Object` in Graal 24 compiled images. More context and investigation in [tracking doc](https://docs.google.com/document/d/1Ij4nmBNsqY3-2GPEpUoGCptrqlKBfv-XOYjb6ly6UcA/edit?resourcekey=0-KaxXkGPeDJQdN61aeT-s1A&tab=t.7jx3c8lk2lvz).
1 parent 0d17261 commit a855eca

File tree

1 file changed

+6
-0
lines changed
  • google-http-client/src/main/java/com/google/api/client/util

1 file changed

+6
-0
lines changed

google-http-client/src/main/java/com/google/api/client/util/Types.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ public static boolean isAssignableToOrFrom(Class<?> classToCheck, Class<?> anoth
106106
* an array or an interface or be abstract. If an enclosing class, it must be static.
107107
*/
108108
public static <T> T newInstance(Class<T> clazz) {
109+
// This is a workaround for https://github.com/oracle/graal/issues/11429. Remove this line once
110+
// the GraalVM team has provided a solution or workaround for this.
111+
if (clazz.getName().equals("java.lang.Object")) {
112+
return (T) new Object();
113+
}
114+
109115
// TODO(yanivi): investigate "sneaky" options for allocating the class that GSON uses, like
110116
// setting the constructor to be accessible, or possibly provide a factory method of a special
111117
// name

0 commit comments

Comments
 (0)