{"record":{"id":"f645c4e8fed110cc","repo":"oracle/graal","slug":"expected-a-non-void-primitive-kind-got","errorCode":null,"errorMessage":"Expected a non-void primitive kind, got {}","messagePattern":"Expected a non-void primitive kind, got (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java","lineNumber":294,"sourceCode":"        Class<?> componentClass = snippetReflection.originalClass(componentType);\n        if (componentClass == null) {\n            throw new IllegalArgumentException(\"Could not obtain the original class for \" + componentType);\n        }\n        Object array = Array.newInstance(componentClass, elements.length);\n        for (int i = 0; i < elements.length; i++) {\n            doWriteArrayElement(array, componentType, i, elements[i]);\n        }\n        return snippetReflection.forObject(array);\n    }\n\n    /**\n     * Host mode materializes the primitive array with reflection and then wraps it as a\n     * {@link JavaConstant} through {@link SnippetReflectionProvider#forObject(Object)}.\n     */\n    @Override\n    public JavaConstant createPrimitiveArray(JavaKind kind, int length) {\n        if (kind == null || !kind.isPrimitive() || kind == JavaKind.Void) {\n            throw new IllegalArgumentException(\"Expected a non-void primitive kind, got \" + kind);\n        }\n        Object array = Array.newInstance(kind.toJavaClass(), length);\n        return providers.getSnippetReflection().forObject(array);\n    }\n\n    @Override\n    public JavaConstant clonePrimitiveArray(JavaConstant primitiveArray) {\n        ResolvedJavaType arrayType = getProviders().getMetaAccess().lookupJavaType(primitiveArray);\n        if (arrayType == null || !arrayType.isArray() || !arrayType.getComponentType().isPrimitive()) {\n            throw new IllegalArgumentException(\"Expected a primitive array constant, got \" + primitiveArray);\n        }\n        Object source = providers.getSnippetReflection().asObject(Object.class, primitiveArray);\n        if (source == null) {\n            throw new IllegalArgumentException(\"Could not unwrap a primitive array constant: \" + primitiveArray);\n        }\n        /*\n         * Keep cloning explicit by primitive array kind. This avoids reflective clone access and\n         * preserves exact array runtime type through each typed clone() call.","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java#L276-L312","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nhostVM.createPrimitiveArray(kindFromSignature, n);  // Object kind -> throws\n\n// after\nif (kindFromSignature != null && kindFromSignature.isPrimitive() && kindFromSignature != JavaKind.Void) {\n    hostVM.createPrimitiveArray(kindFromSignature, n);\n}","handlingStrategy":"type-guard","validationCode":"if (kind == null || !kind.isPrimitive() || kind == JavaKind.Void) {\n    throw new IllegalArgumentException(\"need a primitive kind, got \" + kind);","typeGuard":"static boolean isNonVoidPrimitive(JavaKind k) { return k != null && k.isPrimitive() && k != JavaKind.Void; }","tryCatchPattern":"catch (IllegalArgumentException e) { pick the correct kind from the value/signature and retry }","preventionTips":["Check isPrimitive() && != Void before array creation","Never use Void as a 'no value' placeholder in constant builders","Cover all JavaKind branches exhaustively in switches"],"tags":["graalvm","hostvmaccess","arrays","validation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}