{"record":{"id":"f41f37a81f6a1d8a","repo":"apache/iceberg","slug":"does-not-support-null-keys","errorCode":null,"errorMessage":" does not support null keys","messagePattern":" does not support null keys","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/util/PartitionMap.java","lineNumber":210,"sourceCode":"    PartitionSpec spec = specs.get(entry.getKey());\n    return entry.getValue().entrySet().stream().map(innerEntry -> toString(spec, innerEntry));\n  }\n\n  private String toString(PartitionSpec spec, Entry<StructLike, V> entry) {\n    StructLike struct = entry.getKey();\n    V value = entry.getValue();\n    return spec.partitionToPath(struct) + \" -> \" + (value == this ? \"(this Map)\" : value);\n  }\n\n  private <R> R execute(Object key, BiFunction<Integer, StructLike, R> action, R defaultValue) {\n    if (key instanceof Pair) {\n      Object first = ((Pair<?, ?>) key).first();\n      Object second = ((Pair<?, ?>) key).second();\n      if (first instanceof Integer && (second == null || second instanceof StructLike)) {\n        return action.apply((Integer) first, (StructLike) second);\n      }\n    } else if (key == null) {\n      throw new NullPointerException(getClass().getName() + \" does not support null keys\");\n    }\n\n    return defaultValue;\n  }\n\n  private static class PartitionEntry<V> implements Entry<Pair<Integer, StructLike>, V> {\n    private final int specId;\n    private final Entry<StructLike, V> structAndValue;\n\n    private PartitionEntry(int specId, Entry<StructLike, V> structAndValue) {\n      this.specId = specId;\n      this.structAndValue = structAndValue;\n    }\n\n    @Override\n    public Pair<Integer, StructLike> getKey() {\n      return Pair.of(specId, structAndValue.getKey());\n    }","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/util/PartitionMap.java#L192-L228","documentation":"PartitionMap only supports keys that are Pair<Integer, StructLike> (specId + partition data). When a key is null — which no supported key can be — it throws a NullPointerException naming the class, since a null partition key is meaningless.","triggerScenarios":"Calling get(key, default) (via the doAction path) with key == null on a PartitionMap, typically from generic Map<StructLike, V> code that passes null keys.","commonSituations":"Generic map-processing utilities that pass null; data corrupted by upstream null partition values.","solutions":["Never call get/put with null keys on a PartitionMap","Ensure partition data construction never yields null pairs","Add a null check before accessing the PartitionMap"],"exampleFix":"// before\nmap.get(null, null);\n// after\nif (key != null) { map.get(key, null); }","handlingStrategy":"validation","validationCode":"if (key == null) throw new IllegalArgumentException(\"PartitionMap requires non-null Pair keys\");","typeGuard":"boolean isPartitionKey(Object k) { return k instanceof Pair && ((Pair<?, ?>) k).first() instanceof Integer; }","tryCatchPattern":"try { map.get(key, null); } catch (NullPointerException e) { /* null key path — supply default */ }","preventionTips":["Never feed generic Map code with null keys into PartitionMap","Validate partition data before insertion","Assert keys are Pair<Integer, StructLike> at boundaries"],"tags":["partitionmap","null-key","argument"],"backgroundTag":"null-argument","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}