{"record":{"id":"6fff689aa36901fb","repo":"prestodb/presto","slug":"map-key-cannot-be-null-or-contain-nulls","errorCode":null,"errorMessage":"map key cannot be null or contain nulls","messagePattern":"map key cannot be null or contain nulls","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/MapBlockBuilder.java","lineNumber":587,"sourceCode":"                if (outputHashTable[hashTableOffset + hash] == -1) {\n                    outputHashTable[hashTableOffset + hash] = i;\n                    break;\n                }\n\n                Boolean isDuplicateKey;\n                try {\n                    // assuming maps with indeterminate keys are not supported\n                    isDuplicateKey = (Boolean) keyBlockEquals.invokeExact(keyBlock, keyOffset + i, keyBlock, keyOffset + outputHashTable[hashTableOffset + hash]);\n                }\n                catch (RuntimeException e) {\n                    throw e;\n                }\n                catch (Throwable throwable) {\n                    throw new RuntimeException(throwable);\n                }\n\n                if (isDuplicateKey == null) {\n                    throw new NotSupportedException(\"map key cannot be null or contain nulls\");\n                }\n\n                if (isDuplicateKey) {\n                    throw new DuplicateMapKeyException(keyBlock, keyOffset + i);\n                }\n\n                hash++;\n                if (hash == hashTableSize) {\n                    hash = 0;\n                }\n            }\n        }\n    }\n\n    private static int getHashPosition(Block keyBlock, int position, MethodHandle keyBlockHashCode, int hashTableSize)\n    {\n        if (keyBlock.isNull(position)) {\n            throw new IllegalArgumentException(\"map keys cannot be null\");","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/MapBlockBuilder.java#L569-L605","documentation":"In buildHashTableStrict, the duplicate-key probe returns null when the key block (or a nested row key) contains a null, meaning duplicate detection cannot be performed. The method converts that into NotSupportedException 'map key cannot be null or contain nulls' because strict map building requires every key to be hashable and comparable.","triggerScenarios":"Closing an entry with closeEntryStrict on a MapBlockBuilder whose key block contains null at some position (or a ROW-typed key block containing nulls), causing isDuplicateKey == null.","commonSituations":"Building maps with map_from_entries or similar functions where one entry's key evaluated to NULL; constructing ROW keys where an inner field is NULL.","solutions":["Ensure all key values are non-null before building the map","Filter out null keys / entries upstream (e.g. in the function producing entries)","Use the non-strict entry-close path only if null keys are genuinely impossible to rule out"],"exampleFix":"// before\nbuilder.entryIsNull / builder.closeEntryStrict(); // key NULL present\n// after\ncheckState(!keyBlock.isNull(keyPosition), \"map key cannot be null\");\nbuilder.closeEntryStrict();","handlingStrategy":"validation","validationCode":"for (int i = 0; i < entries.getPositionCount(); i += 2) {\n    if (entries.isNull(i)) {\n        entries = dropNullKeyEntries(entries);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    builder.closeEntryStrict();\n} catch (NotSupportedException e) {\n    // reject input: null or partially-null map key\n}","preventionTips":["Coalesce/reject NULL keys before map construction","Ensure all fields of ROW-typed keys are non-null","Filter null keys in map-producing SQL functions"],"tags":["not-supported","map-block","null-key"],"backgroundTag":"null-map-key","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}