{"record":{"id":"4d64a3806c0bc534","repo":"oracle/graal","slug":"expected-a-non-void-primitive-kind-got-4d64a3","errorCode":null,"errorMessage":"Expected a non-void primitive kind, got {}","messagePattern":"Expected a non-void primitive kind, got (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalVMAccess.java","lineNumber":581,"sourceCode":"                    continue;\n                }\n                if (!(element instanceof EspressoExternalObjectConstant objectElement)) {\n                    throw new IllegalArgumentException(\"Element \" + i + \" should be an espresso object constant, got \" + safeGetClass(element));\n                }\n                try {\n                    array.setArrayElement(i, objectElement.getValue());\n                } catch (ClassCastException e) {\n                    throw new IllegalArgumentException(\"Element \" + i + \" is not an instance of the component type\", e);\n                }\n            }\n        }\n        return new EspressoExternalObjectConstant(this, array);\n    }\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        if (length < 0) {\n            throw new NegativeArraySizeException(\"Negative array size: \" + length);\n        }\n        Value array = invokeJVMCIHelper(\"newPrimitiveArray\", (int) kind.getTypeChar(), 1, length);\n        return new EspressoExternalObjectConstant(this, array);\n    }\n\n    @Override\n    public JavaConstant clonePrimitiveArray(JavaConstant primitiveArray) {\n        if (!(primitiveArray instanceof EspressoExternalObjectConstant objectConstant)) {\n            throw new IllegalArgumentException(\"Expected an EspressoExternalObjectConstant, got \" + safeGetClass(primitiveArray));\n        }\n        EspressoResolvedObjectType arrayType = objectConstant.getType();\n        if (!(arrayType.isArray() && arrayType.getComponentType().isPrimitive())) {\n            throw new IllegalArgumentException(\"Expected a primitive array constant, got \" + arrayType);\n        }\n        Value copy = invokeJVMCIHelper(\"clonePrimitiveArray\", objectConstant.getValue());","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/espresso-compiler-stub/src/com.oracle.truffle.espresso.vmaccess/src/com/oracle/truffle/espresso/vmaccess/EspressoExternalVMAccess.java#L563-L599","documentation":"createPrimitiveArray(kind, length) allocates a guest primitive array via a JVMCI helper that takes the kind's type character; null kinds, reference kinds (Object), and Void have no primitive array representation, so the method rejects them up front with IllegalArgumentException. Only the eight true primitive JavaKinds are accepted.","triggerScenarios":"Calling createPrimitiveArray with JavaKind.Object, JavaKind.Void, or a null kind — often because a kind variable was derived from a generic type or unvalidated input.","commonSituations":"Generic array-building helpers that pass whatever kind a ResolvedJavaType reports without checking isPrimitive(); handling Void from method return kinds; null kind from failed lookups.","solutions":["Guard the call: if (kind != null && kind.isPrimitive() && kind != JavaKind.Void) before creating.","Route object/reference kinds to asArrayConstant with an Object component type instead.","Treat a null kind as an upstream lookup failure and fix the type resolution."],"exampleFix":"// before\nJavaConstant a = vmAccess.createPrimitiveArray(kind, n);\n\n// after\nif (kind != null && kind.isPrimitive() && kind != JavaKind.Void) {\n    JavaConstant a = vmAccess.createPrimitiveArray(kind, n);\n}","handlingStrategy":"validation","validationCode":"if (kind == null || !kind.isPrimitive() || kind == JavaKind.Void) {\n    // reject or route object kinds to asArrayConstant\n}","typeGuard":"static boolean isLegalPrimitiveKind(JavaKind k) {\n    return k != null && k.isPrimitive() && k != JavaKind.Void;\n}","tryCatchPattern":null,"preventionTips":["Never pass a kind straight from a generic type without an isPrimitive() check.","Handle JavaKind.Void (method returns) explicitly before array creation.","Null kind means an earlier lookup failed — fix that first."],"tags":["jvmci","espresso","graalvm","arrays","primitives","validation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}