apache/pulsar · error · NullPointerException
The given bytes are null
Error message
The given bytes are null
What it means
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").
Source
Thrown at tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlockAwareSegmentInputStreamImpl.java:221
entryHeaderBuf.writeInt(entryLength).writeLong(entryId);
entryBuf.addComponents(true, entryHeaderBuf, buf);
entries.add(entryBuf);
}
return entries;
} catch (InterruptedException | ExecutionException e) {
log.error().exception(e).log("Exception when getting LedgerEntries");
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
throw new IOException(e);
}
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException("The given bytes are null");
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException("off=" + off + ", len=" + len + ", b.length=" + b.length);
} else if (len == 0) {
return 0;
}
int offset = off;
int readLen = len;
int readBytes = 0;
// reading header
if (dataBlockHeaderStream.available() > 0) {
int read = dataBlockHeaderStream.read(b, off, len);
offset += read;
readLen -= read;
readBytes += read;
bytesReadOffset += read;
}
if (readLen == 0) {View on GitHub (pinned to 820761864e)
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()
Example fix
// before stream.read(null, 0, len); // NPE // after byte[] buf = new byte[len]; int n = stream.read(buf, 0, len);
Defensive patterns
Strategy: type-guard
Validate before calling
if (b == null) throw new IllegalArgumentException("buffer must not be null");
// then call read safely
int n = stream.read(b, off, len); Type guard
static boolean safeBuffer(byte[] b) { return b != null; }
// usage: if (!safeBuffer(buf)) allocateOrReject(); Try / catch
try {
int n = stream.read(buf, off, len);
} catch (NullPointerException e) {
if ("The given bytes are null".equals(e.getMessage())) {
buf = new byte[len]; n = stream.read(buf, off, len);
} else throw e;
} Prevention
- 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
When it happens
Trigger: Calling read(null, off, len) on the segment input stream — the buffer parameter was never initialized or was set to null by the caller.
Common situations: Caller bug passing an uninitialized byte[] when copying a block to the offload output; wrapper streams forwarding a null buffer obtained elsewhere.
Related errors
- off=${off}, len=${len}, b.length=${b.length}
- Cursor %s mark-delete position %s is ahead of the last posit
- Timeout during reset cursor
- Timeout during mark-delete operation
- Could not open configuration file
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/b91d08f489ccb09f.
Report an issue: GitHub.