oracle/graal · error · IllegalArgumentException

Expected an EspressoExternalObjectConstant for src, got {}

Error message

Expected an EspressoExternalObjectConstant for src, got {}

What it means

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, ...').

Source

Thrown at espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalVMAccess.java:606

    }

    @Override
    public JavaConstant clonePrimitiveArray(JavaConstant primitiveArray) {
        if (!(primitiveArray instanceof EspressoExternalObjectConstant objectConstant)) {
            throw new IllegalArgumentException("Expected an EspressoExternalObjectConstant, got " + safeGetClass(primitiveArray));
        }
        EspressoResolvedObjectType arrayType = objectConstant.getType();
        if (!(arrayType.isArray() && arrayType.getComponentType().isPrimitive())) {
            throw new IllegalArgumentException("Expected a primitive array constant, got " + arrayType);
        }
        Value copy = invokeJVMCIHelper("clonePrimitiveArray", objectConstant.getValue());
        return new EspressoExternalObjectConstant(this, copy);
    }

    @Override
    public void copyArray(JavaConstant src, int srcPos, JavaConstant dest, int destPos, int length) {
        if (!(src instanceof EspressoExternalObjectConstant srcArray)) {
            throw new IllegalArgumentException("Expected an EspressoExternalObjectConstant for src, got " + safeGetClass(src));
        }
        if (!(dest instanceof EspressoExternalObjectConstant destArray)) {
            throw new IllegalArgumentException("Expected an EspressoExternalObjectConstant for dest, got " + safeGetClass(dest));
        }
        if (!srcArray.getType().isArray()) {
            throw new IllegalArgumentException("Expected an array constant for src, got " + srcArray.getType());
        }
        if (!destArray.getType().isArray()) {
            throw new IllegalArgumentException("Expected an array constant for dest, got " + destArray.getType());
        }
        try {
            invoke(java_lang_System_arraycopy, null, srcArray, JavaConstant.forInt(srcPos), destArray, JavaConstant.forInt(destPos), JavaConstant.forInt(length));
        } catch (InvocationException e) {
            if (e.getCause() instanceof PolyglotException polyglotException) {
                throw throwHostException(polyglotException);
            }
            throw e;
        }

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Ensure src was created by the same Espresso provider (createPrimitiveArray / asArrayConstant / guest loads).
  2. Guard src instanceof EspressoExternalObjectConstant and use java.lang.System.arraycopy on the host for host arrays.
  3. Rebuild stale cached constants through the current provider before copying.

Example fix

// before
vmAccess.copyArray(src, 0, dest, 0, n);

// after
if (src instanceof EspressoExternalObjectConstant) {
    vmAccess.copyArray(src, 0, dest, 0, n);
} else {
    System.arraycopy(hostSrc, 0, hostDest, 0, n);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(src instanceof EspressoExternalObjectConstant)) {
    // host src: copy with java.lang.System.arraycopy on the host
}

Type guard

static boolean isEspressoConstant(JavaConstant c) {
    return c instanceof EspressoExternalObjectConstant;
}

Try / catch

catch (IllegalArgumentException e) with 'for src' -> rebuild src via the Espresso provider or copy on the host side.

Prevention

When it happens

Trigger: Calling copyArray with a src produced by host HotSpot constant reflection, JavaConstant.forObject(hostArray), or another Espresso context.

Common situations: Buffer-copy helpers fed from mixed-origin constants; constants cached from an older provider instance; polyglot pipelines moving data between contexts.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/24efba18bb08e209. Report an issue: GitHub.