{"record":{"id":"24efba18bb08e209","repo":"oracle/graal","slug":"expected-an-espressoexternalobjectconstant-for-src","errorCode":null,"errorMessage":"Expected an EspressoExternalObjectConstant for src, got {}","messagePattern":"Expected an EspressoExternalObjectConstant for src, got (.+?)","errorType":"validation","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":606,"sourceCode":"    }\n\n    @Override\n    public JavaConstant clonePrimitiveArray(JavaConstant primitiveArray) {\n        if (!(primitiveArray instanceof EspressoExternalObjectConstant objectConstant)) {\n            throw new IllegalArgumentException(\"Expected an EspressoExternalObjectConstant, got \" + safeGetClass(primitiveArray));\n        }\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        }","sourceCodeStart":588,"sourceCodeEnd":624,"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#L588-L624","documentation":"copyArray(src, srcPos, dest, destPos, length) forwards to the guest's System.arraycopy, so both arguments must be EspressoExternalObjectConstants wrapping guest arrays. A src constant from a foreign JVMCI backend cannot be passed into the guest call and throws IllegalArgumentException('Expected an EspressoExternalObjectConstant for src, ...').","triggerScenarios":"Calling copyArray with a src produced by host HotSpot constant reflection, JavaConstant.forObject(hostArray), or another Espresso context.","commonSituations":"Buffer-copy helpers fed from mixed-origin constants; constants cached from an older provider instance; polyglot pipelines moving data between contexts.","solutions":["Ensure src was created by the same Espresso provider (createPrimitiveArray / asArrayConstant / guest loads).","Guard src instanceof EspressoExternalObjectConstant and use java.lang.System.arraycopy on the host for host arrays.","Rebuild stale cached constants through the current provider before copying."],"exampleFix":"// before\nvmAccess.copyArray(src, 0, dest, 0, n);\n\n// after\nif (src instanceof EspressoExternalObjectConstant) {\n    vmAccess.copyArray(src, 0, dest, 0, n);\n} else {\n    System.arraycopy(hostSrc, 0, hostDest, 0, n);\n}","handlingStrategy":"type-guard","validationCode":"if (!(src instanceof EspressoExternalObjectConstant)) {\n    // host src: copy with java.lang.System.arraycopy on the host\n}","typeGuard":"static boolean isEspressoConstant(JavaConstant c) {\n    return c instanceof EspressoExternalObjectConstant;\n}","tryCatchPattern":"catch (IllegalArgumentException e) with 'for src' -> rebuild src via the Espresso provider or copy on the host side.","preventionTips":["Allocate and copy arrays on the same side of the host/guest boundary.","Avoid JavaConstant.forObject(hostArray) results entering guest copy APIs.","Refresh cached constants after context restarts."],"tags":["jvmci","espresso","graalvm","arrays","constants"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}