{"record":{"id":"e7d85f7bb1ca8684","repo":"oracle/graal","slug":"inputgraph-already-contains-inputnode-with-id","errorCode":null,"errorMessage":"InputGraph already contains InputNode with Id={}","messagePattern":"InputGraph already contains InputNode with Id=(.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/model/InputGraph.java","lineNumber":406,"sourceCode":"        return data().edges.size();\n    }\n\n    public Collection<InputNode> getNodes() {\n        return Collections.unmodifiableCollection(data().nodes.values());\n    }\n\n    public Set<Integer> getNodesAsSet() {\n        return Collections.unmodifiableSet(data().nodes.keySet());\n    }\n\n    public Collection<InputBlock> getBlocks() {\n        return Collections.unmodifiableCollection(data().blocks.values());\n    }\n\n    public void addNode(InputNode node) {\n        assert !isFrozen();\n        if (data().nodes.containsKey(node.getId())) {\n            throw new IllegalStateException(\"InputGraph already contains InputNode with Id=\" + node.getId());\n        }\n        data().nodes.put(node.getId(), node);\n        if (data().highestNodeId < node.getId()) {\n            data().highestNodeId = node.getId();\n        }\n        nodeIds = null;\n    }\n\n    /**\n     * Highest node ID in the graph. Under assumption that node IDs are assigned sequentially\n     * (though some IDs may be missing), the value may allow some preallocations or optimizations.\n     * Returns -1 for empty graph with no nodes.\n     *\n     * @return highest node ID.\n     */\n    public int getHighestNodeId() {\n        return data().highestNodeId;\n    }","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/model/InputGraph.java#L388-L424","documentation":"InputGraph.addNode stores nodes keyed by their integer id and rejects a second node with the same id. The IllegalStateException signals corrupt or duplicated input while a graph is being assembled (typically during graph-dump loading), preserving the id-uniqueness invariant other components rely on.","triggerScenarios":"Calling InputGraph.addNode(node) twice for the same InputNode id, or adding two distinct InputNodes with equal getId() while a dump is being parsed or a graph is built programmatically; also reachable when a lazy data() section is initialized twice from the same source.","commonSituations":"Loading a malformed/hand-edited .bgv dump where NEW_NODE entries repeat an id; merging two graphs by copying nodes without re-mapping ids; replay logic that re-adds nodes after a partial failure.","solutions":["Before adding, check graph.findNode(id)/getNodesAsSet() and skip or re-map the id when it already exists","Re-assign unique ids when merging graphs (use getHighestNodeId() as the starting offset)","If loading from a dump, re-generate the dump from a healthy compilation instead of hand-editing it"],"exampleFix":"// before\ngraph.addNode(newNode); // id already present\n\n// after\nif (graph.getNodesAsSet().contains(newNode.getId())) {\n    newNode.setId(nextFreshId(graph));\n}\ngraph.addNode(newNode);","handlingStrategy":"validation","validationCode":"if (graph.getNodesAsSet().contains(node.getId())) { /* skip, error out, or re-map id before addNode */ }","typeGuard":null,"tryCatchPattern":"try { graph.addNode(n); } catch (IllegalStateException e) { /* log dump corruption; abort load of this graph, keep others */ }","preventionTips":["Validate id uniqueness while parsing dump entries","Re-map ids when merging graphs starting from getHighestNodeId()","Never hand-edit NEW_NODE ids in .bgv dumps"],"tags":["graphio","data-integrity","graph-model"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}