{"record":{"id":"89b405120cf62a21","repo":"oracle/graal","slug":"could-not-load-graal-nodeclass-type-field-for","errorCode":null,"errorMessage":"Could not load Graal NodeClass TYPE field for ","messagePattern":"Could not load Graal NodeClass TYPE field for ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graph/NodeClass.java","lineNumber":117,"sourceCode":"    public static <T> NodeClass<T> create(Class<T> c) {\n        assert getUnchecked(c) == null;\n        Class<? super T> superclass = c.getSuperclass();\n        NodeClass<? super T> nodeSuperclass = null;\n        if (superclass != NODE_CLASS) {\n            nodeSuperclass = get(superclass);\n        }\n        return new NodeClass<>(c, nodeSuperclass);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @LibGraalSupport.HostedOnly\n    private static <T> NodeClass<T> getUnchecked(Class<T> clazz) {\n        try {\n            Field field = clazz.getDeclaredField(\"TYPE\");\n            field.setAccessible(true);\n            return (NodeClass<T>) field.get(null);\n        } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {\n            throw new RuntimeException(\"Could not load Graal NodeClass TYPE field for \" + clazz, e);\n        }\n    }\n\n    @LibGraalSupport.HostedOnly\n    public static <T> NodeClass<T> get(Class<T> clazz) {\n        NodeClass<T> result = getUnchecked(clazz);\n        if (result == null && clazz != NODE_CLASS) {\n            throw GraalError.shouldNotReachHere(\"TYPE field not initialized for class \" + clazz.getTypeName()); // ExcludeFromJacocoGeneratedReport\n        }\n        return result;\n    }\n\n    private static final Class<?> NODE_CLASS = Node.class;\n    private static final Class<?> INPUT_LIST_CLASS = NodeInputList.class;\n    private static final Class<?> SUCCESSOR_LIST_CLASS = NodeSuccessorList.class;\n\n    private static final AtomicInteger nextIterableId = new AtomicInteger();\n    private static final AtomicInteger nextLeafId = new AtomicInteger();","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graph/NodeClass.java#L99-L135","documentation":"NodeClass.getUnchecked reflectively reads the static field TYPE from a node class to obtain its NodeClass metadata. The RuntimeException wraps reflection failures: NoSuchFieldException (the class is not a Graal node or TYPE was never generated/initialized), IllegalAccessException/SecurityException (setAccessible(true) denied by JPMS or a security manager), or IllegalArgumentException. It is HostedOnly, i.e. used in the libgraal hosted runtime where node metadata is resolved via reflection.","triggerScenarios":"Calling NodeClass.get(clazz) where clazz has no public/static TYPE field (not a Node subclass, or class-level initialization not run), or running under a module policy that blocks deep reflection into the node's package. Also classloader tricks that re-load node classes without running their static initializers.","commonSituations":"Custom node classes whose static initializer did not run before metadata lookup. Strict JPMS builds or --illegal-access=deny style configurations that block setAccessible. Passing arbitrary classes (e.g. Object.class) into NodeClass.get instead of real node classes. Version skew between a node library and the compiler expecting a TYPE field.","solutions":["Ensure the class is a real Graal Node subclass whose static initializer creates TYPE (generated by the NodeInfo/NodeClass processor).","Force class initialization before lookup: Class.forName(clazz.getName(), true, clazz.getClassLoader()).","Add opens/exports for the node's package so setAccessible(true) is permitted (--add-opens java.base/... or module-info opens).","Verify you are passing the node class you think you are (log clazz.getName()) and that only one classloader loaded it."],"exampleFix":"// before\nNodeClass<MyNode> nc = NodeClass.get(MyNode.class); // TYPE not initialized -> wrap of NoSuchFieldException\n\n// after\nClass.forName(\"com.example.MyNode\", true, MyNode.class.getClassLoader()); // run static init\nNodeClass<MyNode> nc = NodeClass.get(MyNode.class);","handlingStrategy":"try-catch","validationCode":"try {\n    Field f = clazz.getDeclaredField(\"TYPE\");\n    f.setAccessible(true);\n    if (f.get(null) == null) throw new IllegalStateException(\"TYPE not initialized: \" + clazz);\n} catch (ReflectiveOperationException | SecurityException e) {\n    // initialize or fix module opens before calling NodeClass.get\n    Class.forName(clazz.getName(), true, clazz.getClassLoader());\n}","typeGuard":"static boolean hasNodeClassMetadata(Class<?> c) {\n    try {\n        Field f = c.getDeclaredField(\"TYPE\");\n        f.setAccessible(true);\n        return f.get(null) != null;\n    } catch (ReflectiveOperationException | SecurityException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    NodeClass<T> nc = NodeClass.get(clazz);\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof NoSuchFieldException) {\n        throw new IllegalStateException(clazz + \" is not a Graal node class (no TYPE field)\", e);\n    }\n    if (e.getCause() instanceof SecurityException || e.getCause() instanceof IllegalAccessException) {\n        throw new IllegalStateException(\"Reflection blocked: add --add-opens for \" + clazz.getPackage().getName(), e);\n    }\n    throw e;\n}","preventionTips":["Only pass classes generated by the Graal annotation processor into NodeClass.get.","In JPMS deployments, open the packages containing your node classes to the compiler.","Ensure node classes are initialized (referenced/Class.forName) before hosted-time metadata lookup."],"tags":["java","graal","graal-compiler","reflection","nodeclass","jpms","metadata"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}