oracle/graal · error · IllegalStateException

Could not find a parent for group

Error message

Could not find a parent for group 

What it means

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.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/ModelBuilder.java:579

    }

    @Override
    public void endDocumentHeader() {
        if (newProperties == null) {
            throw new IllegalStateException("Unexpected end document header");
        }
        documentLevelProperties = newProperties;
        newProperties = null;
    }

    private GraphDocument resolveDocument(Properties props, Group g) {
        if (rootDocument != null) {
            return rootDocument;
        }
        rootDocument = rootDocumentFactory.documentFor(documentId, props, g);

        if (rootDocument == null) {
            throw new IllegalStateException("Could not find a parent for group " + folder);
        }
        rootDocumentResolved(rootDocument);
        return rootDocument;
    }

    @Override
    public void startGroupContent() {
        assert folder instanceof Group;
        Group g = (Group) folder;
        Folder parent = getParent();
        // If the parent is null, it's not decided yet, and must be determined
        // based on the new group's properties. Failure to do so will
        // throw an exception.
        if (parent == null) {
            parent = resolveDocument(documentLevelProperties, g);
            g.setParent(parent);
        }
        registerToParent(parent, folder);

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Make your RootDocumentFactory.documentFor create a new GraphDocument (or return a sensible default) instead of returning null.
  2. If the factory routes by documentId, register the expected ids before parsing or fall back to a default document.
  3. Add a defensive check/log inside documentFor so refusals are visible with the documentId that missed.

Example fix

// before
GraphDocument documentFor(Object id, Properties p, Group g) {
    return registry.lookup(id); // null when id is unknown -> IllegalStateException
}

// after
GraphDocument documentFor(Object id, Properties p, Group g) {
    GraphDocument d = registry.lookup(id);
    return d != null ? d : new GraphDocument(String.valueOf(id));
}
Defensive patterns

Strategy: fallback

Validate before calling

GraphDocument d = factory.documentFor(id, props, g);
if (d == null) { throw new IllegalStateException("RootDocumentFactory returned null for id " + id); }

Try / catch

try { parser.parse(); } catch (IllegalStateException e) { if (e.getMessage().startsWith("Could not find a parent for group")) { /* fix factory: never return null */ } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/9c986747a77137c8. Report an issue: GitHub.