{"record":{"id":"882b6cfd0360c40b","repo":"oracle/graal","slug":"isempty-is-not-supported-for-performance-reasons","errorCode":null,"errorMessage":"isEmpty() is not supported for performance reasons","messagePattern":"isEmpty\\(\\) is not supported for performance reasons","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graph/NodeMap.java","lineNumber":87,"sourceCode":"        return (T) values[getNodeId(node)];\n    }\n\n    private void checkAndGrow(Node node) {\n        if (isNew(node)) {\n            this.values = Arrays.copyOf(values, Math.max(MIN_REALLOC_SIZE, graph.nodeIdCount() * 3 / 2));\n        }\n        assert check(node);\n    }\n\n    public void growToSize(int newSize) {\n        if (newSize > this.values.length) {\n            this.values = Arrays.copyOf(values, Math.max(MIN_REALLOC_SIZE, newSize));\n        }\n    }\n\n    @Override\n    public boolean isEmpty() {\n        throw new UnsupportedOperationException(\"isEmpty() is not supported for performance reasons\");\n    }\n\n    @Override\n    public boolean containsKey(Node node) {\n        if (node.graph() == graph()) {\n            return get(node) != null;\n        }\n        return false;\n    }\n\n    public Graph graph() {\n        return graph;\n    }\n\n    public void set(Node node, T value) {\n        assert check(node);\n        if (!node.isAlive()) {\n            throw new GraalGraphError(\"this node is not alive: \" + node);","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graph/NodeMap.java#L69-L105","documentation":"NodeMap is an array keyed by node id, not a general map: it has no element count and tracking one would add bookkeeping to a hot data structure. isEmpty() therefore throws UnsupportedOperationException instead of giving a wrong or slow answer. Capacity is available via capacity(), and membership semantics differ from java.util.Map (containsKey requires the node to belong to the map's graph).","triggerScenarios":"Calling nodeMap.isEmpty() directly, or handing a NodeMap to code that treats it as a Map (debuggers, toString helpers, generic Map utilities, assertion libraries) that probes isEmpty().","commonSituations":"Passing NodeMap into java.util.Map-oriented helper code or test assertion utilities. IDE-generated equals/isEmpty delegation. Refactoring from HashMap<Node,T> to NodeMap and leaving an isEmpty() call behind.","solutions":["Remove the isEmpty() call; track emptiness with your own counter or boolean alongside the NodeMap.","Use map.get(node) != null for per-node presence checks (with containsKey for membership semantics).","If generic Map compatibility is required, copy into a HashMap at a phase boundary instead of using NodeMap directly in that code."],"exampleFix":"// before\nif (map.isEmpty()) { ... } // NodeMap throws\n\n// after\nif (populatedCount == 0) { ... } // maintain alongside the NodeMap","handlingStrategy":"validation","validationCode":"// never call map.isEmpty(); maintain presence knowledge yourself\nboolean nothingSet = entriesSetByCaller == 0;\nboolean nodePresent = map.get(node) != null;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Before adopting NodeMap, grep your code for Map-shaped calls (isEmpty, size) and replace them.","Keep a parallel counter or boolean when you need emptiness semantics.","Do not pass NodeMap to toString/log helpers that introspect Maps."],"tags":["java","graal","graal-compiler","unsupported-operation","nodemap","api-misuse"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}