oracle/graal · error · IllegalArgumentException
Expected a non-void primitive kind, got {}
Error message
Expected a non-void primitive kind, got {} What it means
Thrown by HostVMAccess.createPrimitiveArray when the requested JavaKind is null, not primitive, or Void. Array creation needs a concrete primitive class (kind.toJavaClass()), so reference kinds and void are rejected up front.
Source
Thrown at compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java:294
Class<?> componentClass = snippetReflection.originalClass(componentType);
if (componentClass == null) {
throw new IllegalArgumentException("Could not obtain the original class for " + componentType);
}
Object array = Array.newInstance(componentClass, elements.length);
for (int i = 0; i < elements.length; i++) {
doWriteArrayElement(array, componentType, i, elements[i]);
}
return snippetReflection.forObject(array);
}
/**
* Host mode materializes the primitive array with reflection and then wraps it as a
* {@link JavaConstant} through {@link SnippetReflectionProvider#forObject(Object)}.
*/
@Override
public JavaConstant createPrimitiveArray(JavaKind kind, int length) {
if (kind == null || !kind.isPrimitive() || kind == JavaKind.Void) {
throw new IllegalArgumentException("Expected a non-void primitive kind, got " + kind);
}
Object array = Array.newInstance(kind.toJavaClass(), length);
return providers.getSnippetReflection().forObject(array);
}
@Override
public JavaConstant clonePrimitiveArray(JavaConstant primitiveArray) {
ResolvedJavaType arrayType = getProviders().getMetaAccess().lookupJavaType(primitiveArray);
if (arrayType == null || !arrayType.isArray() || !arrayType.getComponentType().isPrimitive()) {
throw new IllegalArgumentException("Expected a primitive array constant, got " + primitiveArray);
}
Object source = providers.getSnippetReflection().asObject(Object.class, primitiveArray);
if (source == null) {
throw new IllegalArgumentException("Could not unwrap a primitive array constant: " + primitiveArray);
}
/*
* Keep cloning explicit by primitive array kind. This avoids reflective clone access and
* preserves exact array runtime type through each typed clone() call.View on GitHub (pinned to a66e9ccd1d)
Solutions
- Pass one of the eight primitive kinds (Boolean, Byte, Short, Char, Int, Long, Float, Double)
- Branch on kind.isPrimitive() && kind != JavaKind.Void before calling
- Map 'no value' to skipping the call rather than passing Void
Example fix
// before
hostVM.createPrimitiveArray(kindFromSignature, n); // Object kind -> throws
// after
if (kindFromSignature != null && kindFromSignature.isPrimitive() && kindFromSignature != JavaKind.Void) {
hostVM.createPrimitiveArray(kindFromSignature, n);
} Defensive patterns
Strategy: type-guard
Validate before calling
if (kind == null || !kind.isPrimitive() || kind == JavaKind.Void) {
throw new IllegalArgumentException("need a primitive kind, got " + kind); Type guard
static boolean isNonVoidPrimitive(JavaKind k) { return k != null && k.isPrimitive() && k != JavaKind.Void; } Try / catch
catch (IllegalArgumentException e) { pick the correct kind from the value/signature and retry } Prevention
- Check isPrimitive() && != Void before array creation
- Never use Void as a 'no value' placeholder in constant builders
- Cover all JavaKind branches exhaustively in switches
When it happens
Trigger: Calling createPrimitiveArray(kind, length) with kind == null, an object kind like JavaKind.Object/Illegal, or JavaKind.Void; length is not validated here (negative length surfaces later as NegativeArraySizeException from Array.newInstance).
Common situations: Forwarding a kind obtained from a value or signature without checking isPrimitive(); using JavaKind.Void as a placeholder for 'no value' in generic constant-building code; defaulting a kind variable to null on an unhandled branch.
Related errors
- Expected an array constant for src, got {}
- Expected an array constant for dest, 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/f645c4e8fed110cc.
Report an issue: GitHub.