diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/SimulateClassInitializerGraphDecoder.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/SimulateClassInitializerGraphDecoder.java index 02d2eb09cf05..d757991a844c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/SimulateClassInitializerGraphDecoder.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/SimulateClassInitializerGraphDecoder.java @@ -346,9 +346,12 @@ protected boolean handleArrayCopy(ImageHeapArray source, int sourcePos, ImageHea } if (destComponentType.getJavaKind() == JavaKind.Object && !destComponentType.isJavaLangObject() && !sourceComponentType.equals(destComponentType)) { for (int i = 0; i < length; i++) { - var elementValueType = ((TypedConstant) source.getElement(sourcePos + i)).getType(metaAccess); - if (!destComponentType.isAssignableFrom(elementValueType)) { - return false; + var elementValue = (JavaConstant) source.getElement(sourcePos + i); + if (elementValue.isNonNull()) { + var elementValueType = ((TypedConstant) elementValue).getType(metaAccess); + if (!destComponentType.isAssignableFrom(elementValueType)) { + return false; + } } } } diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/clinit/TestClassInitialization.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/clinit/TestClassInitialization.java index ffa6fad54a78..983a46edc6e9 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/clinit/TestClassInitialization.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/clinit/TestClassInitialization.java @@ -612,7 +612,7 @@ public static Object defaultValue(Class clazz) { System.arraycopy(shorts, 1, S1, 2, 5); System.arraycopy(S1, 3, S1, 5, 5); - Object[] objects = {"42", "43", "44", "45", "46", "47", "48"}; + Object[] objects = {"42", null, "44", "45", null, "47", "48"}; O1 = Arrays.copyOf(objects, 3); O2 = Arrays.copyOfRange(objects, 3, 6, String[].class); } @@ -943,8 +943,8 @@ public static void main(String[] args) { assertSame(Short.class, BoxingMustBeSimulated.defaultValue(short.class).getClass()); assertSame(Float.class, BoxingMustBeSimulated.defaultValue(float.class).getClass()); assertTrue(Arrays.equals((short[]) BoxingMustBeSimulated.S1, new short[]{0, 0, 43, 44, 45, 44, 45, 46, 47, 0, 0, 0})); - assertTrue(Arrays.equals((Object[]) BoxingMustBeSimulated.O1, new Object[]{"42", "43", "44"})); - assertTrue(Arrays.equals((Object[]) BoxingMustBeSimulated.O2, new String[]{"45", "46", "47"})); + assertTrue(Arrays.equals((Object[]) BoxingMustBeSimulated.O1, new Object[]{"42", null, "44"})); + assertTrue(Arrays.equals((Object[]) BoxingMustBeSimulated.O2, new String[]{"45", null, "47"})); /* * The unsafe field offset lookup is constant folded at image build time, which also