{"record":{"id":"49318001ef4c3b7b","repo":"prestodb/presto","slug":"map-keys-must-not-be-null","errorCode":null,"errorMessage":"Map keys must not be null","messagePattern":"Map keys must not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/block/MapBlockBuilder.java","lineNumber":424,"sourceCode":"    @Override\n    public BlockBuilder appendStructure(Block block)\n    {\n        if (!(block instanceof SingleMapBlock)) {\n            throw new IllegalArgumentException(\"Expected SingleMapBlock\");\n        }\n        if (currentEntryOpened) {\n            throw new IllegalStateException(\"Expected current entry to be closed but was opened\");\n        }\n        currentEntryOpened = true;\n\n        SingleMapBlock singleMapBlock = (SingleMapBlock) block;\n        int blockPositionCount = singleMapBlock.getPositionCount();\n        if (blockPositionCount % 2 != 0) {\n            throw new IllegalArgumentException(format(\"block position count is not even: %s\", blockPositionCount));\n        }\n        for (int i = 0; i < blockPositionCount; i += 2) {\n            if (singleMapBlock.isNull(i)) {\n                throw new IllegalArgumentException(\"Map keys must not be null\");\n            }\n            else {\n                singleMapBlock.writePositionTo(i, keyBlockBuilder);\n            }\n            if (singleMapBlock.isNull(i + 1)) {\n                valueBlockBuilder.appendNull();\n            }\n            else {\n                singleMapBlock.writePositionTo(i + 1, valueBlockBuilder);\n            }\n        }\n\n        closeEntry(singleMapBlock.getHashTable(), singleMapBlock.getOffsetBase() / 2 * HASH_MULTIPLIER);\n        return this;\n    }\n\n    @Override\n    public BlockBuilder appendStructureInternal(Block block, int position)","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/block/MapBlockBuilder.java#L406-L442","documentation":"appendStructure copies an existing map block into this MapBlockBuilder key-by-key. Presto maps forbid null keys, so when a key position in the source block is null the builder throws IllegalArgumentException rather than producing a corrupt map. Keys may be null only in unchecked SQL modes at the source, but internally the invariant must hold.","triggerScenarios":"Calling MapBlockBuilder.appendStructure (or writeBlock/appendStructure paths) with a source singleMapBlock whose even positions (keys) contain a null at any key slot.","commonSituations":"Copying a deserialized or untrusted block built outside strict validation; test code constructing maps with null keys; data round-tripped from engines that allow null map keys.","solutions":["Ensure the source map block never contains null keys before appending","Filter or drop entries whose keys are null before building the map","Validate with an IS NULL check on key positions in producing code"],"exampleFix":"// before\nmapBlockBuilder.appendStructure(singleMapBlock);\n// after\nfor (int i = 0; i < singleMapBlock.getPositionCount(); i += 2) {\n    checkState(!singleMapBlock.isNull(i), \"null key in source map\");\n}\nmapBlockBuilder.appendStructure(singleMapBlock);","handlingStrategy":"validation","validationCode":"for (int i = 0; i < singleMapBlock.getPositionCount(); i += 2) {\n    if (singleMapBlock.isNull(i)) {\n        throw new IllegalArgumentException(\"source map has null key at \" + i);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    builder.appendStructure(singleMapBlock);\n} catch (IllegalArgumentException e) {\n    // rebuild map without null keys\n}","preventionTips":["Never construct map entries with NULL keys","Validate source blocks before appending","Enforce non-null keys at the data producer boundary"],"tags":["illegal-argument","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"}