oracle/graal · error · IllegalArgumentException
Expected an array constant for dest, got {}
Error message
Expected an array constant for dest, got {} What it means
Thrown by HostVMAccess.copyArray when the dest constant cannot be unwrapped to a live host array object: asObject(Object.class, dest) returned null or its class is not an array. It is the destination-side twin of the src guard, checked just before System.arraycopy.
Source
Thrown at compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java:336
case char[] array -> array.clone();
case int[] array -> array.clone();
case long[] array -> array.clone();
case float[] array -> array.clone();
case double[] array -> array.clone();
default -> throw new IllegalArgumentException("Expected a primitive array constant, got " + primitiveArray);
};
return providers.getSnippetReflection().forObject(copy);
}
@Override
public void copyArray(JavaConstant src, int srcPos, JavaConstant dest, int destPos, int length) {
Object srcArray = providers.getSnippetReflection().asObject(Object.class, src);
if (srcArray == null || !srcArray.getClass().isArray()) {
throw new IllegalArgumentException("Expected an array constant for src, got " + src);
}
Object destArray = providers.getSnippetReflection().asObject(Object.class, dest);
if (destArray == null || !destArray.getClass().isArray()) {
throw new IllegalArgumentException("Expected an array constant for dest, got " + dest);
}
System.arraycopy(srcArray, srcPos, destArray, destPos, length);
}
private void doWriteArrayElement(Object array, ResolvedJavaType componentType, int index, JavaConstant element) {
Object unwrappedValue;
if (componentType.isPrimitive()) {
if (componentType.getJavaKind() != element.getJavaKind()) {
throw new IllegalArgumentException("Element " + element + " should be a " + componentType.getJavaKind() + ", got " + element.getJavaKind());
}
unwrappedValue = element.asBoxedPrimitive();
} else {
if (!element.getJavaKind().isObject()) {
throw new IllegalArgumentException("Element " + element + " should be an object, got " + componentType);
}
unwrappedValue = providers.getSnippetReflection().asObject(Object.class, element);
}
Array.set(array, index, unwrappedValue);View on GitHub (pinned to a66e9ccd1d)
Solutions
- Materialize the destination with asArrayConstant(componentType, ...) (or forObject over a real array) before copying
- Verify dest unwraps to an array object before the call, mirroring the guard
- Double-check src/dest argument order and that dest length >= destPos + length
Example fix
// before hostVM.copyArray(srcConstant, 0, unmaterializedDestConstant, 0, n); // throws // after JavaConstant dest = hostVM.asArrayConstant(componentType, new JavaConstant[n]); hostVM.copyArray(srcConstant, 0, dest, 0, n);
Defensive patterns
Strategy: validation
Validate before calling
Object d = snippetReflection.asObject(Object.class, dest);
if (d == null || !d.getClass().isArray() || Array.getLength(d) < destPos + length) {
throw new IllegalArgumentException("dest not a sufficiently large array: " + dest); Type guard
static boolean isLiveArrayConstant(JavaConstant c, SnippetReflectionProvider sp) {
Object o = sp.asObject(Object.class, c);
return o != null && o.getClass().isArray();
} Try / catch
catch (IllegalArgumentException e) { allocate dest with asArrayConstant of the right length and retry } Prevention
- Allocate the destination before the copy, sized destPos+length
- Never reuse the src variable for dest by copy-paste
- Assert capacity of both arrays in test harnesses before copyArray
When it happens
Trigger: Calling copyArray with a dest constant that is null-valued, a non-array constant, or not backed by a host object; also reached when src and dest are swapped in the argument list so dest receives a scalar constant.
Common situations: Destination arrays not yet materialized (created only as type plans rather than via asArrayConstant); reusing a src constant variable for dest by mistake; constants deserialized from another context without object backing.
Related errors
- Expected a non-void primitive kind, got {}
- Expected an array constant for src, got {}
- Could not obtain the original class for {}
- Expected a primitive array constant, got {}
- Could not unwrap a primitive array constant: {}
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/807f1128859a579c.
Report an issue: GitHub.