{"record":{"id":"8dd1d624385ec5c2","repo":"prestodb/presto","slug":"generic-internal-error-8dd1d6","errorCode":"GENERIC_INTERNAL_ERROR","errorMessage":"Map must never contain null keys","messagePattern":"Map must never contain null keys","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-rcfile/src/main/java/com/facebook/presto/rcfile/text/MapEncoding.java","lineNumber":53,"sourceCode":"            TextColumnEncoding valueEncoding)\n    {\n        super(type, nullSequence, separators, escapeByte);\n        this.keyEncoding = keyEncoding;\n        this.valueEncoding = valueEncoding;\n    }\n\n    @Override\n    public void encodeValueInto(int depth, Block block, int position, SliceOutput output)\n            throws RcFileCorruptionException\n    {\n        byte elementSeparator = getSeparator(depth);\n        byte keyValueSeparator = getSeparator(depth + 1);\n\n        Block map = block.getBlock(position);\n        boolean first = true;\n        for (int elementIndex = 0; elementIndex < map.getPositionCount(); elementIndex += 2) {\n            if (map.isNull(elementIndex)) {\n                throw new PrestoException(StandardErrorCode.GENERIC_INTERNAL_ERROR, \"Map must never contain null keys\");\n            }\n\n            if (!first) {\n                output.writeByte(elementSeparator);\n            }\n            first = false;\n            keyEncoding.encodeValueInto(depth + 2, map, elementIndex, output);\n            output.writeByte(keyValueSeparator);\n            if (map.isNull(elementIndex + 1)) {\n                output.writeBytes(nullSequence);\n            }\n            else {\n                valueEncoding.encodeValueInto(depth + 2, map, elementIndex + 1, output);\n            }\n        }\n    }\n\n    @Override","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-rcfile/src/main/java/com/facebook/presto/rcfile/text/MapEncoding.java#L35-L71","documentation":"Text MapEncoding serializes maps as delimited text and has no way to represent a null key. A null key violates Presto's map invariant, so encodeValueInto throws PrestoException(GENERIC_INTERNAL_ERROR) rather than silently emitting malformed text.","triggerScenarios":"encodeValueInto iterating a map Block where position elementIndex (a key slot, even index) isNull — only possible from a non-conforming MapBlock producer (connector, UDF, extension code).","commonSituations":"Custom connectors or UDFs constructing map blocks with null keys; bugs in block-building extension code; unit-test fixtures violating the map contract.","solutions":["Fix the block producer to reject or replace null keys before encoding","Add an upstream guard that filters null keys from the map (e.g. transform/filter block construction)","Re-express the map in SQL with map_filter to drop null keys","Catch PrestoException(GENERIC_INTERNAL_ERROR) and file a bug against the producing component"],"exampleFix":"// before\nmap.put(null, v);\n// after\nif (key != null) { map.put(key, v); } // or map_filter(m, (k, v) -> k IS NOT NULL)","handlingStrategy":"validation","validationCode":"// before text-encoding a nested map\nBlock map = block.getBlock(position);\nfor (int i = 0; i < map.getPositionCount(); i += 2) {\n    if (map.isNull(i)) { throw new IllegalArgumentException(\"null map key at \" + i); }\n}","typeGuard":null,"tryCatchPattern":"try { stringMapEncoding.encodeValueInto(depth, block, position, output); }\ncatch (PrestoException e) {\n    if (e.getErrorCode().getCode() == StandardErrorCode.GENERIC_INTERNAL_ERROR.toErrorCode().getCode()) {\n        reportBug(e); // producer built a map with a null key\n    } else { throw e; }\n}","preventionTips":["Assert no-null-keys in map block builders used by connectors/UDFs","Test nested map encoding with edge-case fixtures","Use map_filter in SQL to drop null keys before writing","File/track producer bugs immediately — this is an invariant failure, not user data"],"tags":["rcfile","text-encoding","map","null-keys","internal-error"],"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"}