oracle/graal · error · IllegalArgumentException
Expected an array constant for src, got
Error message
Expected an array constant for src, got
What it means
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.
Source
Thrown at espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalVMAccess.java:612
}
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;
}
}
@Override
public void writeArrayElement(JavaConstant array, int index, JavaConstant element) {
if (!(array instanceof EspressoExternalObjectConstant espressoArray)) {
throw new IllegalArgumentException("Expected an EspressoExternalObjectConstant, got " + safeGetClass(array));View on GitHub (pinned to a66e9ccd1d)
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.
Example fix
// before vmAccess.copyArray(stringConstant, 0, dest, 0, n); // after assert ((EspressoExternalObjectConstant) src).getType().isArray(); vmAccess.copyArray(src, 0, dest, 0, n);
Defensive patterns
Strategy: validation
Validate before calling
if (src instanceof EspressoExternalObjectConstant e && !e.getType().isArray()) {
// wrong constant: locate the enclosing array constant before copying
} Type guard
static boolean isGuestArray(JavaConstant c) {
return c instanceof EspressoExternalObjectConstant e && e.getType().isArray();
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Expected a non-void primitive kind, got {}
- Expected an array constant for dest, got
- Expected an array type, got
- Invalid component type
- Element {} should be a {} but was {}
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/1c1b871dcd1c4ecf.
Report an issue: GitHub.