{"record":{"id":"8c40b868054bba09","repo":"apache/druid","slug":"hllsketchholder-fromobj-cannot-take-a-null-argumen","errorCode":null,"errorMessage":"HllSketchHolder.fromObj cannot take a null argument","messagePattern":"HllSketchHolder\\.fromObj cannot take a null argument","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/HllSketchHolder.java","lineNumber":35,"sourceCode":" * under the License.\n */\n\npackage org.apache.druid.query.aggregation.datasketches.hll;\n\nimport com.fasterxml.jackson.annotation.JsonValue;\nimport org.apache.datasketches.hll.HllSketch;\nimport org.apache.datasketches.hll.TgtHllType;\nimport org.apache.datasketches.hll.Union;\nimport org.apache.datasketches.memory.Memory;\nimport org.apache.druid.java.util.common.ISE;\nimport org.apache.druid.java.util.common.StringUtils;\n\npublic class HllSketchHolder\n{\n  public static HllSketchHolder fromObj(Object obj)\n  {\n    if (obj == null) {\n      throw new NullPointerException(\"HllSketchHolder.fromObj cannot take a null argument\");\n    }\n\n    if (obj instanceof HllSketchHolder) {\n      return (HllSketchHolder) obj;\n    } else if (obj instanceof HllSketch) {\n      return HllSketchHolder.of((HllSketch) obj);\n    } else if (obj instanceof Union) {\n      return HllSketchHolder.of((Union) obj);\n    } else if (obj instanceof byte[]) {\n      return HllSketchHolder.of(HllSketch.heapify((byte[]) obj));\n    } else if (obj instanceof Memory) {\n      return HllSketchHolder.of(HllSketch.wrap((Memory) obj));\n    } else if (obj instanceof String) {\n      return HllSketchHolder.of(HllSketch.heapify(StringUtils.decodeBase64(StringUtils.toUtf8((String) obj))));\n    }\n\n    throw new ISE(\"Object is not of a type[%s] that can be deserialized to sketch.\", obj.getClass());\n  }","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/HllSketchHolder.java#L17-L53","documentation":"HllSketchHolder.fromObj is the deserialization entry point for HLL sketch aggregation objects and explicitly rejects null input with a NullPointerException. The library requires callers to pass a HllSketchHolder, HllSketch, Memory, or base64 String; null carries no recoverable meaning. Throwing early makes upstream data-pipeline bugs (e.g. missing aggregator rows) fail fast instead of corrupting results.","triggerScenarios":"Calling HllSketchHolder.fromObj(null) directly, or indirectly when an aggregation selector/row returns null for a sketch column (e.g. deserializing a null aggregator value from a segment or query result).","commonSituations":"Reading Druid segments where the HLL metric column is absent for some rows; passing a null combined-aggregator value into a post-aggregator; custom aggregation code that forwards raw column objects without null checks.","solutions":["Check the object for null before calling fromObj and skip/default the row instead","Fix the ingestion spec so the HLL metric column is present and serialized for all rows","If null is legitimate, wrap the call and treat null as an empty sketch (HllSketchHolder.of(new HllSketch(...)) or a zeros-filled result)"],"exampleFix":"// before\nHllSketchHolder holder = HllSketchHolder.fromObj(row.get(\"sketch\"));\n// after\nObject obj = row.get(\"sketch\");\nHllSketchHolder holder = obj == null ? HllSketchHolder.of(new HllSketch(12)) : HllSketchHolder.fromObj(obj);","handlingStrategy":"type-guard","validationCode":"if (obj == null) { throw new IllegalArgumentException(\"sketch column value is null\"); }","typeGuard":"boolean isUsableSketchInput(Object o) { return o instanceof HllSketchHolder || o instanceof HllSketch || o instanceof Memory || o instanceof String; }","tryCatchPattern":"try { holder = HllSketchHolder.fromObj(obj); } catch (NullPointerException e) { holder = HllSketchHolder.of(new HllSketch(12)); }","preventionTips":["Null-check aggregator column values before deserialization","Ensure ingestion specs always serialize the sketch metric","Wrap fromObj calls in a small utility that defaults nulls to an empty sketch"],"tags":["null","deserialization","datasketches","hll"],"backgroundTag":"null-argument","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}