{"record":{"id":"3fe617a6d1b44e84","repo":"apache/druid","slug":"input-stream-is-null","errorCode":null,"errorMessage":"Input stream is null","messagePattern":"Input stream is null","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/filter/BloomKFilter.java","lineNumber":163,"sourceCode":"    dataOutputStream.writeInt(bloomFilter.getBitSet().length);\n    for (long value : bloomFilter.getBitSet()) {\n      dataOutputStream.writeLong(value);\n    }\n  }\n\n  /**\n   * Deserialize a bloom filter\n   * Read a byte stream, which was written by {@linkplain #serialize(OutputStream, BloomKFilter)}\n   * into a {@code BloomKFilter}\n   *\n   * @param in input bytestream\n   *\n   * @return deserialized BloomKFilter\n   */\n  public static BloomKFilter deserialize(InputStream in) throws IOException\n  {\n    if (in == null) {\n      throw new IOException(\"Input stream is null\");\n    }\n\n    try {\n      DataInputStream dataInputStream = new DataInputStream(in);\n      int numHashFunc = dataInputStream.readByte();\n      int bitsetArrayLen = dataInputStream.readInt();\n      long[] data = new long[bitsetArrayLen];\n      for (int i = 0; i < bitsetArrayLen; i++) {\n        data[i] = dataInputStream.readLong();\n      }\n      return new BloomKFilter(data, numHashFunc);\n    }\n    catch (RuntimeException e) {\n      IOException io = new IOException(\"Unable to deserialize BloomKFilter\");\n      io.initCause(e);\n      throw io;\n    }\n  }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/druid-bloom-filter/src/main/java/org/apache/druid/query/filter/BloomKFilter.java#L145-L181","documentation":"BloomKFilter.deserialize(InputStream) validates its input before parsing the binary bloom filter format and throws IOException('Input stream is null') when given a null stream. The binary format (numHashFunc byte, bitset length int, then longs) cannot be read from a null source, so it fails fast.","triggerScenarios":"Calling BloomKFilter.deserialize(null), e.g. when a lookup/base64-decoded payload or byte source produced null (missing column value, failed decode, unset variable) and the result is passed straight into deserialize.","commonSituations":"Reading persisted bloom filter payloads from a database/blob store where the row has no filter stored; deserializing an optional JSON field that was absent; wrapping a base64 field that failed to decode and left the stream null.","solutions":["Check the stream for null before calling deserialize and treat null as 'no filter' (create an empty BloomKFilter(maxNumEntries) instead)","Fix the upstream producer so a valid serialized filter is always stored (empty filter rather than null)","Add logging/assertions where the stream is created to find why it is null"],"exampleFix":"// before\nBloomKFilter filter = BloomKFilter.deserialize(in); // NPE/IOE when in == null\n// after\nBloomKFilter filter = (in == null) ? new BloomKFilter(maxNumEntries) : BloomKFilter.deserialize(in);","handlingStrategy":"type-guard","validationCode":"// Java guard before deserializing\nif (in == null) { return new BloomKFilter(maxNumEntries); } // empty filter fallback","typeGuard":"static boolean isReadable(InputStream in) { return in != null; }","tryCatchPattern":"try {\n  return BloomKFilter.deserialize(in);\n} catch (IOException e) {\n  if (\"Input stream is null\".equals(e.getMessage())) {\n    return new BloomKFilter(maxNumEntries); // treat as no filter\n  }\n  throw e;\n}","preventionTips":["Null-check streams returned from DB/blob lookups before deserializing","Default missing payloads to an empty BloomKFilter(maxNumEntries)","Log when the source payload is absent to fix producers"],"tags":["druid","bloom-filter","null-argument","deserialization","io"],"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"}