{"record":{"id":"1c1b871dcd1c4ecf","repo":"oracle/graal","slug":"expected-an-array-constant-for-src-got-1c1b87","errorCode":null,"errorMessage":"Expected an array constant for src, got ","messagePattern":"Expected an array constant for src, got ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalVMAccess.java","lineNumber":612,"sourceCode":"        }\n        EspressoResolvedObjectType arrayType = objectConstant.getType();\n        if (!(arrayType.isArray() && arrayType.getComponentType().isPrimitive())) {\n            throw new IllegalArgumentException(\"Expected a primitive array constant, got \" + arrayType);\n        }\n        Value copy = invokeJVMCIHelper(\"clonePrimitiveArray\", objectConstant.getValue());\n        return new EspressoExternalObjectConstant(this, copy);\n    }\n\n    @Override\n    public void copyArray(JavaConstant src, int srcPos, JavaConstant dest, int destPos, int length) {\n        if (!(src instanceof EspressoExternalObjectConstant srcArray)) {\n            throw new IllegalArgumentException(\"Expected an EspressoExternalObjectConstant for src, got \" + safeGetClass(src));\n        }\n        if (!(dest instanceof EspressoExternalObjectConstant destArray)) {\n            throw new IllegalArgumentException(\"Expected an EspressoExternalObjectConstant for dest, got \" + safeGetClass(dest));\n        }\n        if (!srcArray.getType().isArray()) {\n            throw new IllegalArgumentException(\"Expected an array constant for src, got \" + srcArray.getType());\n        }\n        if (!destArray.getType().isArray()) {\n            throw new IllegalArgumentException(\"Expected an array constant for dest, got \" + destArray.getType());\n        }\n        try {\n            invoke(java_lang_System_arraycopy, null, srcArray, JavaConstant.forInt(srcPos), destArray, JavaConstant.forInt(destPos), JavaConstant.forInt(length));\n        } catch (InvocationException e) {\n            if (e.getCause() instanceof PolyglotException polyglotException) {\n                throw throwHostException(polyglotException);\n            }\n            throw e;\n        }\n    }\n\n    @Override\n    public void writeArrayElement(JavaConstant array, int index, JavaConstant element) {\n        if (!(array instanceof EspressoExternalObjectConstant espressoArray)) {\n            throw new IllegalArgumentException(\"Expected an EspressoExternalObjectConstant, got \" + safeGetClass(array));","sourceCodeStart":594,"sourceCodeEnd":630,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalVMAccess.java#L594-L630","documentation":"After both constants pass the Espresso check, copyArray verifies the src constant's guest type is actually an array type (isArray()), since System.arraycopy only accepts arrays. A non-array Espresso constant (a plain object, string, or class mirror) is rejected with IllegalArgumentException naming its type.","triggerScenarios":"Passing an Espresso object constant that is not an array — e.g. a String constant, a single boxed value, or a Class mirror — as src to copyArray.","commonSituations":"Variable mix-ups where an element is passed instead of its enclosing array; generic data-movement code that receives any constant; refactors changing what a variable holds.","solutions":["Check srcArray.getType().isArray() (on the EspressoExternalObjectConstant) before calling copyArray.","Fix the upstream variable so it references the array constant, not an element or unrelated object.","Add an assert/log of the constant type at the call site during development."],"exampleFix":"// before\nvmAccess.copyArray(stringConstant, 0, dest, 0, n);\n\n// after\nassert ((EspressoExternalObjectConstant) src).getType().isArray();\nvmAccess.copyArray(src, 0, dest, 0, n);","handlingStrategy":"validation","validationCode":"if (src instanceof EspressoExternalObjectConstant e && !e.getType().isArray()) {\n    // wrong constant: locate the enclosing array constant before copying\n}","typeGuard":"static boolean isGuestArray(JavaConstant c) {\n    return c instanceof EspressoExternalObjectConstant e && e.getType().isArray();\n}","tryCatchPattern":null,"preventionTips":["Assert the constant's type isArray() at copy call sites during development.","Name variables arrayXxx vs elementXxx to avoid element/array mix-ups.","Log constant types when generic data-movement code handles mixed constants."],"tags":["jvmci","espresso","graalvm","arrays","validation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}