{"record":{"id":"f5b589b372562737","repo":"oracle/graal","slug":"could-not-obtain-the-original-class-for","errorCode":null,"errorMessage":"Could not obtain the original class for {}","messagePattern":"Could not obtain the original class for (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java","lineNumber":278,"sourceCode":"    @SuppressWarnings(\"deprecation\")\n    static <T extends AccessibleObject & Member> void makeAccessible(T accessibleMember) {\n        try {\n            if (!accessibleMember.isAccessible()) {\n                accessibleMember.setAccessible(true);\n            }\n        } catch (InaccessibleObjectException e) {\n            Class<?> declaringClass = accessibleMember.getDeclaringClass();\n            ModuleSupport.addOpens(HostVMAccess.class.getModule(), declaringClass.getModule(), declaringClass.getPackageName());\n            accessibleMember.setAccessible(true);\n        }\n    }\n\n    @Override\n    public JavaConstant asArrayConstant(ResolvedJavaType componentType, JavaConstant... elements) {\n        SnippetReflectionProvider snippetReflection = providers.getSnippetReflection();\n        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);","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler.hostvmaccess/src/jdk/graal/compiler/hostvmaccess/HostVMAccess.java#L260-L296","documentation":"Thrown by HostVMAccess.asArrayConstant when SnippetReflectionProvider.originalClass(componentType) returns null for the requested component type, i.e. the ResolvedJavaType has no original (host) Class mirror available for array creation via Array.newInstance.","triggerScenarios":"Calling asArrayConstant(componentType, elements) where componentType is a hotswapped/substituted type, an unresolved or array-of-array type the snippet reflection cannot map, or a type from a class loading context invisible to the host. Note this checks the component type only — a null elements array still triggers a later NullPointerException inside the loop.","commonSituations":"Building host-side array constants during snippet unfolding for types that only exist in the compiled/guest world; using a MetaAccess from a different universe (e.g. image heap vs host); passing an unresolved ResolvedJavaType obtained lazily without a resolution step.","solutions":["Resolve the component type first (e.g. type.resolve(), or obtain it via metaAccess.lookupJavaType(realClass))","If the type is a substitution, look up the original type via the snippet reflection's substitution machinery before calling asArrayConstant","Pass a component type derived from an existing host Class mirror to guarantee originalClass succeeds"],"exampleFix":"// before\nhostVM.asArrayConstant(unresolvedOrSubstitutedType, e0, e1);  // throws\n\n// after\nResolvedJavaType resolved = metaAccess.lookupJavaType(String.class); // concrete host class\nhostVM.asArrayConstant(resolved, e0, e1);","handlingStrategy":"validation","validationCode":"Class<?> c = snippetReflection.originalClass(componentType);\nif (c == null) throw new IllegalArgumentException(\"no original class for \" + componentType);","typeGuard":"static boolean hasOriginalClass(ResolvedJavaType t, SnippetReflectionProvider s) { return s.originalClass(t) != null; }","tryCatchPattern":"catch (IllegalArgumentException e) { resolve/substitute the type via metaAccess and retry once }","preventionTips":["Prefer component types obtained from metaAccess.lookupJavaType(Class)","Resolve substituted/unresolved types before host array creation","Keep providers from a single universe/context"],"tags":["graalvm","hostvmaccess","reflection","arrays","type-resolution"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}