{"record":{"id":"60e3072c46285f72","repo":"oracle/graal","slug":"invalid-component-type","errorCode":null,"errorMessage":"Invalid component type","messagePattern":"Invalid component type","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":532,"sourceCode":"    public JavaConstant invoke(ResolvedJavaMethod method, JavaConstant receiver, JavaConstant... arguments) {\n        if (!(method instanceof EspressoExternalResolvedJavaMethod espressoMethod)) {\n            throw new IllegalArgumentException(\"Expected an EspressoExternalResolvedJavaMethod, got \" + safeGetClass(method));\n        }\n        return espressoMethod.invoke(receiver, arguments);\n    }\n\n    @Override\n    public void writeField(ResolvedJavaField field, JavaConstant receiver, JavaConstant value) {\n        if (!(field instanceof EspressoExternalResolvedJavaField espressoField)) {\n            throw new IllegalArgumentException(\"Expected an EspressoExternalResolvedJavaField, got \" + safeGetClass(field));\n        }\n        espressoField.writeValue(receiver, value);\n    }\n\n    @Override\n    public JavaConstant asArrayConstant(ResolvedJavaType componentType, JavaConstant... elements) {\n        if (!(componentType.getArrayClass() instanceof EspressoExternalResolvedArrayType arrayType)) {\n            throw new IllegalArgumentException(\"Invalid component type\");\n        }\n        EspressoResolvedJavaType elementalType = arrayType.getElementalType();\n        Value array;\n        boolean isPrimitiveArray;\n        int dimensions = arrayType.getDimensions();\n        if (elementalType instanceof EspressoExternalResolvedInstanceType elementalInstanceType) {\n            array = invokeJVMCIHelper(\"newObjectArray\", elementalInstanceType.getMetaObject(), dimensions, elements.length);\n            isPrimitiveArray = false;\n        } else {\n            JavaKind javaKind = elementalType.getJavaKind();\n            assert javaKind.isPrimitive() && javaKind != JavaKind.Void;\n            array = invokeJVMCIHelper(\"newPrimitiveArray\", (int) javaKind.getTypeChar(), dimensions, elements.length);\n            isPrimitiveArray = dimensions == 1;\n        }\n        if (isPrimitiveArray) {\n            JavaKind javaKind = elementalType.getJavaKind();\n            for (int i = 0; i < elements.length; i++) {\n                JavaConstant element = elements[i];","sourceCodeStart":514,"sourceCodeEnd":550,"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#L514-L550","documentation":"asArrayConstant(componentType, elements) builds a guest array via a JVMCI helper inside the Espresso VM. The component type's array class must be an EspressoExternalResolvedArrayType — the only implementation that knows the elemental type and dimension count to pass to the guest helper newObjectArray/newPrimitiveArray. A foreign component type has no guest array class, so construction cannot proceed and throws IllegalArgumentException('Invalid component type').","triggerScenarios":"Passing a componentType resolved by the host HotSpot meta access or another JVMCI backend; passing a type whose getArrayClass() is not an EspressoExternalResolvedArrayType (e.g. primitive types whose array class is host-built).","commonSituations":"Building constant arrays for substitutions or folded values with types obtained from the wrong MetaAccessProvider; migrating code from HotSpot JVMCI to Espresso where component types now come from a different source.","solutions":["Resolve componentType through the Espresso external meta access (lookupJavaType on this context) before calling asArrayConstant.","Guard with componentType.getArrayClass() instanceof EspressoExternalResolvedArrayType and fall back to the owning provider otherwise.","Ensure the providers instance passed to EspressoExternalVMAccess is consistent for all type lookups in the call path."],"exampleFix":"// before\nJavaConstant arr = vmAccess.asArrayConstant(componentType, elems);\n\n// after\nif (componentType.getArrayClass() instanceof EspressoExternalResolvedArrayType) {\n    JavaConstant arr = vmAccess.asArrayConstant(componentType, elems);\n} else {\n    JavaConstant arr = foreignAccess.asArrayConstant(componentType, elems);\n}","handlingStrategy":"type-guard","validationCode":"if (!(componentType.getArrayClass() instanceof EspressoExternalResolvedArrayType)) {\n    // re-resolve componentType through Espresso meta access first\n}","typeGuard":"static boolean isEspressoArrayComponent(ResolvedJavaType t) {\n    return t.getArrayClass() instanceof EspressoExternalResolvedArrayType;\n}","tryCatchPattern":"catch (IllegalArgumentException e) with 'Invalid component type' -> re-lookup the type via lookupJavaType and retry once; otherwise propagate.","preventionTips":["Resolve component types via the same Espresso context used for array creation.","Validate the array class type before assembling elements.","Watch for primitive component types whose array class may be host-built."],"tags":["jvmci","espresso","graalvm","arrays","constants"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}