{"record":{"id":"9c986747a77137c8","repo":"oracle/graal","slug":"could-not-find-a-parent-for-group","errorCode":null,"errorMessage":"Could not find a parent for group ","messagePattern":"Could not find a parent for group ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/ModelBuilder.java","lineNumber":579,"sourceCode":"    }\n\n    @Override\n    public void endDocumentHeader() {\n        if (newProperties == null) {\n            throw new IllegalStateException(\"Unexpected end document header\");\n        }\n        documentLevelProperties = newProperties;\n        newProperties = null;\n    }\n\n    private GraphDocument resolveDocument(Properties props, Group g) {\n        if (rootDocument != null) {\n            return rootDocument;\n        }\n        rootDocument = rootDocumentFactory.documentFor(documentId, props, g);\n\n        if (rootDocument == null) {\n            throw new IllegalStateException(\"Could not find a parent for group \" + folder);\n        }\n        rootDocumentResolved(rootDocument);\n        return rootDocument;\n    }\n\n    @Override\n    public void startGroupContent() {\n        assert folder instanceof Group;\n        Group g = (Group) folder;\n        Folder parent = getParent();\n        // If the parent is null, it's not decided yet, and must be determined\n        // based on the new group's properties. Failure to do so will\n        // throw an exception.\n        if (parent == null) {\n            parent = resolveDocument(documentLevelProperties, g);\n            g.setParent(parent);\n        }\n        registerToParent(parent, folder);","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/ModelBuilder.java#L561-L597","documentation":"When the first group arrives, ModelBuilder.resolveDocument asks the configured RootDocumentFactory to create (or locate) the GraphDocument that will contain the dump. If documentFor returns null, there is no container to attach the group to, and IllegalStateException('Could not find a parent for group ...') is thrown. This is a configuration problem in the embedding code: the factory is expected to always produce or reuse a document for the incoming stream.","triggerScenarios":"Constructing a GraphParser/ModelBuilder with a custom RootDocumentFactory whose documentFor returns null (e.g. lookup-by-documentId that misses); factories that only accept specific document ids and reject others; factory state not initialized before parsing.","commonSituations":"Embedding the graph reader in tooling that multiplexes several documents; ID-based document routing where the id in the file is unknown to the factory; refactors that changed document-creation semantics.","solutions":["Make your RootDocumentFactory.documentFor create a new GraphDocument (or return a sensible default) instead of returning null.","If the factory routes by documentId, register the expected ids before parsing or fall back to a default document.","Add a defensive check/log inside documentFor so refusals are visible with the documentId that missed."],"exampleFix":"// before\nGraphDocument documentFor(Object id, Properties p, Group g) {\n    return registry.lookup(id); // null when id is unknown -> IllegalStateException\n}\n\n// after\nGraphDocument documentFor(Object id, Properties p, Group g) {\n    GraphDocument d = registry.lookup(id);\n    return d != null ? d : new GraphDocument(String.valueOf(id));\n}","handlingStrategy":"fallback","validationCode":"GraphDocument d = factory.documentFor(id, props, g);\nif (d == null) { throw new IllegalStateException(\"RootDocumentFactory returned null for id \" + id); }","typeGuard":null,"tryCatchPattern":"try { parser.parse(); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"Could not find a parent for group\")) { /* fix factory: never return null */ } }","preventionTips":["RootDocumentFactory implementations must always return a document; create a default one on miss.","Register all expected document ids before starting to parse multi-document streams.","Log documentId inside documentFor when a lookup misses."],"tags":["graphio","model-builder","configuration","document-factory"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}