{"record":{"id":"b91d08f489ccb09f","repo":"apache/pulsar","slug":"the-given-bytes-are-null","errorCode":null,"errorMessage":"The given bytes are null","messagePattern":"The given bytes are null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlockAwareSegmentInputStreamImpl.java","lineNumber":221,"sourceCode":"                entryHeaderBuf.writeInt(entryLength).writeLong(entryId);\n                entryBuf.addComponents(true, entryHeaderBuf, buf);\n\n                entries.add(entryBuf);\n            }\n            return entries;\n        } catch (InterruptedException | ExecutionException e) {\n            log.error().exception(e).log(\"Exception when getting LedgerEntries\");\n            if (e instanceof InterruptedException) {\n                Thread.currentThread().interrupt();\n            }\n            throw new IOException(e);\n        }\n    }\n\n    @Override\n    public int read(byte[] b, int off, int len) throws IOException {\n        if (b == null) {\n            throw new NullPointerException(\"The given bytes are null\");\n        } else if (off < 0 || len < 0 || len > b.length - off) {\n            throw new IndexOutOfBoundsException(\"off=\" + off + \", len=\" + len + \", b.length=\" + b.length);\n        } else if (len == 0) {\n            return 0;\n        }\n\n        int offset = off;\n        int readLen = len;\n        int readBytes = 0;\n        // reading header\n        if (dataBlockHeaderStream.available() > 0) {\n            int read = dataBlockHeaderStream.read(b, off, len);\n            offset += read;\n            readLen -= read;\n            readBytes += read;\n            bytesReadOffset += read;\n        }\n        if (readLen == 0) {","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlockAwareSegmentInputStreamImpl.java#L203-L239","documentation":"BlockAwareSegmentInputStreamImpl.read(byte[], int, int) validates its arguments per the InputStream contract. A null buffer is rejected immediately with NullPointerException(\"The given bytes are null\").","triggerScenarios":"Calling read(null, off, len) on the segment input stream — the buffer parameter was never initialized or was set to null by the caller.","commonSituations":"Caller bug passing an uninitialized byte[] when copying a block to the offload output; wrapper streams forwarding a null buffer obtained elsewhere.","solutions":["Pass a non-null allocated buffer, e.g. new byte[blockSize]","Audit the calling code path for uninitialized buffer variables","Check wrapper/copy utilities that may pass null through to read()"],"exampleFix":"// before\nstream.read(null, 0, len); // NPE\n// after\nbyte[] buf = new byte[len];\nint n = stream.read(buf, 0, len);","handlingStrategy":"type-guard","validationCode":"if (b == null) throw new IllegalArgumentException(\"buffer must not be null\");\n// then call read safely\nint n = stream.read(b, off, len);","typeGuard":"static boolean safeBuffer(byte[] b) { return b != null; }\n// usage: if (!safeBuffer(buf)) allocateOrReject();","tryCatchPattern":"try {\n  int n = stream.read(buf, off, len);\n} catch (NullPointerException e) {\n  if (\"The given bytes are null\".equals(e.getMessage())) {\n    buf = new byte[len]; n = stream.read(buf, off, len);\n  } else throw e;\n}","preventionTips":["Initialize buffers explicitly before read loops","Run static analysis / null-checks on wrapper stream code","Don't forward buffers from callers that may return null"],"tags":["nullpointer","io","inputstream"],"backgroundTag":"null-buffer-argument","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}