{"record":{"id":"adc942e2c3b34644","repo":"apache/druid","slug":"object-cannot-be-deserialized-to-a-spectator-histo","errorCode":null,"errorMessage":"Object cannot be deserialized to a Spectator Histogram ","messagePattern":"Object cannot be deserialized to a Spectator Histogram ","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogram.java","lineNumber":184,"sourceCode":"        HashMap<String, Long> map = JSON_MAPPER.readerFor(HashMap.class).readValue((String) serializedHistogram);\n        SpectatorHistogram histogram = new SpectatorHistogram();\n        for (Map.Entry<String, Long> entry : map.entrySet()) {\n          histogram.add(entry.getKey(), entry.getValue());\n        }\n        return histogram;\n      }\n      catch (JsonProcessingException e) {\n        throw new ParseException((String) serializedHistogram, e, \"String cannot be deserialized as JSON to a Spectator Histogram\");\n      }\n    }\n    if (serializedHistogram instanceof HashMap) {\n      SpectatorHistogram histogram = new SpectatorHistogram();\n      for (Map.Entry<?, ?> entry : ((HashMap<?, ?>) serializedHistogram).entrySet()) {\n        histogram.add(entry.getKey(), (Number) entry.getValue());\n      }\n      return histogram;\n    }\n    throw new ParseException(\n        null,\n        \"Object cannot be deserialized to a Spectator Histogram \"\n        + serializedHistogram.getClass()\n    );\n  }\n\n  @Nullable\n  static SpectatorHistogram fromByteBuffer(ByteBuffer buffer)\n  {\n    if (buffer == null || !buffer.hasRemaining()) {\n      return null;\n    }\n    SpectatorHistogram histogram = new SpectatorHistogram();\n    while (buffer.hasRemaining()) {\n      short key = buffer.getShort();\n      short idx = (short) (key & KEY_MASK);\n      long val;\n      if ((key & LOW_COUNT_FLAG) == LOW_COUNT_FLAG) {","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogram.java#L166-L202","documentation":"SpectatorHistogram.deserialize expects the incoming object to be a HashMap whose keys are bucket indices and whose values are counts (Numbers). If the serialized object is any other type, the library cannot rebuild a histogram and throws this ParseException. It exists to fail fast on malformed or unexpected payloads rather than silently producing an empty histogram.","triggerScenarios":"Calling SpectatorHistogram.deserialize(Object) with a value that is not a HashMap — e.g. a plain Number, String, List, or a custom map type produced by a different serializer version.","commonSituations":"A Druid segment or query payload was serialized by an older/newer serializer that wraps histograms differently; a user hand-crafted JSON for a post-aggregator where the histogram is a scalar; deserializing a field that was never actually a SpectatorHistogram (column type confusion).","solutions":["Check that the value passed to deserialize is a HashMap of bucket-index -> count before calling it; reject or log other types upstream.","Verify the serialization side uses SpectatorHistogram.serialize / the matching serde so the payload shape matches.","If ingesting JSON, make sure the column is declared with the spectator histogram sketch type, not a plain numeric column."],"exampleFix":"// before\nObject obj = row.get(\"hist\");\nSpectatorHistogram h = SpectatorHistogram.deserialize(obj);\n// after\nif (!(obj instanceof HashMap)) {\n  throw new IAE(\"Expected serialized histogram map, got \" + obj.getClass());\n}\nSpectatorHistogram h = SpectatorHistogram.deserialize(obj);","handlingStrategy":"type-guard","validationCode":"if (obj == null || !(obj instanceof HashMap)) {\n  throw new IAE(\"Cannot deserialize \" + (obj == null ? \"null\" : obj.getClass()) + \" as SpectatorHistogram\");\n}","typeGuard":"boolean isSerializedHistogram(Object o) {\n  return o instanceof HashMap;\n}","tryCatchPattern":"try {\n  SpectatorHistogram h = SpectatorHistogram.deserialize(obj);\n} catch (ParseException e) {\n  log.warn(e, \"Bad histogram payload: %s\", obj == null ? \"null\" : obj.getClass());\n  h = new SpectatorHistogram();\n}","preventionTips":["Only deserialize payloads produced by SpectatorHistogram's own serde.","Type-check with instanceof before calling deserialize.","Pin matching versions of the extension on ingestion and query nodes."],"tags":["deserialization","parse-exception","type-mismatch"],"backgroundTag":"json-unmarshal-failed","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"}