{"record":{"id":"c4ab45be89233f4a","repo":"oracle/graal","slug":"expected-an-array-constant-for-dest-got-c4ab45","errorCode":null,"errorMessage":"Expected an array constant for dest, got ","messagePattern":"Expected an array constant for dest, 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":615,"sourceCode":"            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));\n        }\n        EspressoResolvedObjectType arrayType = espressoArray.getType();\n        if (!arrayType.isArray()) {","sourceCodeStart":597,"sourceCodeEnd":633,"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#L597-L633","documentation":"copyArray's final guard requires the destination constant's guest type to be an array type before dispatching to the guest System.arraycopy. Passing a non-array Espresso constant as dest throws IllegalArgumentException('Expected an array constant for dest, ...') with the type that was found, preventing a doomed cross-language call.","triggerScenarios":"Using an Espresso object constant that is not an array (a single object, string, or mirror) as the copy destination.","commonSituations":"Destination variable shadowed or reassigned to a scalar; builder code that allocates the destination lazily and passes a placeholder; copy-paste of call sites with swapped src/dest.","solutions":["Validate dest's type with isArray() before the call.","Allocate the destination via createPrimitiveArray or asArrayConstant.","Double-check src/dest argument order — a swapped scalar argument typically trips this guard."],"exampleFix":"// before\nvmAccess.copyArray(src, 0, someObjectConstant, 0, n); // swapped/wrong dest\n\n// after\nJavaConstant dest = vmAccess.createPrimitiveArray(JavaKind.Byte, n);\nvmAccess.copyArray(src, 0, dest, 0, n);","handlingStrategy":"validation","validationCode":"if (dest instanceof EspressoExternalObjectConstant e && !e.getType().isArray()) {\n    dest = vmAccess.createPrimitiveArray(kind, neededLength);\n}","typeGuard":"static boolean isGuestArray(JavaConstant c) {\n    return c instanceof EspressoExternalObjectConstant e && e.getType().isArray();\n}","tryCatchPattern":null,"preventionTips":["Double-check src/dest argument order at every copyArray call.","Allocate destinations explicitly before copying.","Beware placeholder constants in lazily-allocated buffers."],"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"}