{"record":{"id":"7722032c13859690","repo":"oracle/graal","slug":"null-not-supported","errorCode":null,"errorMessage":"null not supported","messagePattern":"null not supported","errorType":"validation","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdk/src/org.graalvm.collections/src/org/graalvm/collections/EconomicMapImpl.java","lineNumber":681,"sourceCode":"        checkNonNull(key);\n        int index;\n        if (hasHashArray()) {\n            index = this.findAndRemoveHash(key);\n        } else {\n            index = this.findLinear(key);\n        }\n\n        if (index != -1) {\n            Object value = getValue(index);\n            remove(index);\n            return (V) value;\n        }\n        return null;\n    }\n\n    static void checkNonNull(Object key) {\n        if (key == null) {\n            throw new UnsupportedOperationException(\"null not supported\");\n        }\n    }\n\n    /**\n     * Removes the element at the specific index and returns the index of the next element. This can\n     * be a different value if graph compression was triggered.\n     */\n    private int remove(int indexToRemove) {\n        int index = indexToRemove;\n        int entriesAfterIndex = totalEntries - index - 1;\n        int result = index + 1;\n\n        // Without hash array, compress immediately.\n        if (entriesAfterIndex <= COMPRESS_IMMEDIATE_CAPACITY && !hasHashArray()) {\n            while (index < totalEntries - 1) {\n                setKey(index, getKey(index + 1));\n                setRawValue(index, getRawValue(index + 1));\n                index++;","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/sdk/src/org.graalvm.collections/src/org/graalvm/collections/EconomicMapImpl.java#L663-L699","documentation":"org.graalvm.collections (EconomicMap/EconomicSet) does not permit null keys or elements by design. EconomicMapImpl.checkNonNull is invoked by most map/set operations (put, get, get(default), removeKey, contains, add, remove) and throws UnsupportedOperationException('null not supported') whenever a null key or element is passed. Unlike java.util.HashMap, null is never silently tolerated.","triggerScenarios":"Calling EconomicMap.put(null, v), map.get(null), map.removeKey(null), map.containsKey(null), EconomicSet.add(null), set.contains(null), or any EconomicStorage method routed through EconomicMapImpl.checkNonNull with a null argument. Also hit indirectly when EconomicMap.wrap(java.util.Map) or EconomicSet.wrap(Set) is given a JDK map/set that actually contains a null key/element.","commonSituations":"Porting code from java.util.HashMap/HashSet (which allow null keys) to EconomicMap/EconomicSet for memory/speed; data-driven lookups where a map lookup key comes from an optional field that was never null-checked; wrapping an external Map that contains nulls (e.g. parsed config or JSON with nulls).","solutions":["Null-check keys/elements before every EconomicMap/EconomicSet call, or use a sentinel value (e.g. a static EMPTY_KEY object) instead of null.","Audit the data source feeding the map: if a null key is legitimate, store it in a java.util.HashMap alongside the EconomicMap, or normalize nulls to a sentinel at insertion time.","If wrapping a JDK collection with EconomicMap.wrap/ EconomicSet.wrap, filter or reject null keys/elements in the source collection first."],"exampleFix":"// before\nObject cached = map.get(someField.getId()); // getId() may return null\n\n// after\nObject id = someField.getId();\nObject cached = (id != null) ? map.get(id) : null;","handlingStrategy":"validation","validationCode":"static <K> boolean isUsableKey(K key) {\n    return key != null;\n}\n// EconomicMap.map -> Objects.requireNonNull(key, \"EconomicMap forbids null keys\");","typeGuard":null,"tryCatchPattern":"Catch UnsupportedOperationException at the boundary that accepts external keys, rethrow as IllegalArgumentException with your key's provenance so the null source is identifiable.","preventionTips":["Never port null-tolerant HashMap logic to EconomicMap without a null audit.","Wrap external keys: normalize null to a sentinel constant at the data edge.","Assert keys non-null in debug builds to catch null producers early."],"tags":["graalvm","collections","null-safety","economic-map"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}