apache/iceberg · error · NullPointerException
does not support null keys
Error message
does not support null keys
What it means
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.
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
Example fix
// before
map.get(null, null);
// after
if (key != null) { map.get(key, null); } Defensive patterns
Strategy: validation
Validate before calling
if (key == null) throw new IllegalArgumentException("PartitionMap requires non-null Pair keys"); Type guard
boolean isPartitionKey(Object k) { return k instanceof Pair && ((Pair<?, ?>) k).first() instanceof Integer; } Try / catch
try { map.get(key, null); } catch (NullPointerException e) { /* null key path — supply default */ } Prevention
- Never feed generic Map code with null keys into PartitionMap
- Validate partition data before insertion
- Assert keys are Pair<Integer, StructLike> at boundaries
When it happens
Trigger: 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.
Common situations: Generic map-processing utilities that pass null; data corrupted by upstream null partition values.
Related errors
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/f41f37a81f6a1d8a.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/apache/iceberg/util/PartitionMap.java:210
PartitionSpec spec = specs.get(entry.getKey());
return entry.getValue().entrySet().stream().map(innerEntry -> toString(spec, innerEntry));
}
private String toString(PartitionSpec spec, Entry<StructLike, V> entry) {
StructLike struct = entry.getKey();
V value = entry.getValue();
return spec.partitionToPath(struct) + " -> " + (value == this ? "(this Map)" : value);
}
private <R> R execute(Object key, BiFunction<Integer, StructLike, R> action, R defaultValue) {
if (key instanceof Pair) {
Object first = ((Pair<?, ?>) key).first();
Object second = ((Pair<?, ?>) key).second();
if (first instanceof Integer && (second == null || second instanceof StructLike)) {
return action.apply((Integer) first, (StructLike) second);
}
} else if (key == null) {
throw new NullPointerException(getClass().getName() + " does not support null keys");
}
return defaultValue;
}
private static class PartitionEntry<V> implements Entry<Pair<Integer, StructLike>, V> {
private final int specId;
private final Entry<StructLike, V> structAndValue;
private PartitionEntry(int specId, Entry<StructLike, V> structAndValue) {
this.specId = specId;
this.structAndValue = structAndValue;
}
@Override
public Pair<Integer, StructLike> getKey() {
return Pair.of(specId, structAndValue.getKey());
}View on GitHub (pinned to 86d9c8fc54)