redis/jedis · error · IllegalArgumentException
Buffer size <= 0
Error message
Buffer size <= 0
What it means
RedisInputStream wraps an InputStream with an internal buffer for the RESP protocol parser. The constructor validates that the requested buffer size is positive and throws IllegalArgumentException("Buffer size <= 0") otherwise, because a zero/negative buffer cannot hold any bytes.
Solutions
- Pass a positive size (use the no-arg constructor RedisInputStream(in) to get the default INPUT_BUFFER_SIZE).
- Clamp/validate your configured size before construction: Math.max(minBufferSize, configuredSize).
- If the size is computed, check the computation for overflow or zero-division results.
Example fix
// before int size = config.getBufferSize(); // 0 when unset RedisInputStream in = new RedisInputStream(raw, size); // throws // after int size = Math.max(1024, config.getBufferSize()); RedisInputStream in = new RedisInputStream(raw, size);
Defensive patterns
Strategy: validation
Validate before calling
static RedisInputStream safeWrap(InputStream in, int size) {
if (size <= 0) size = 8192; // or use RedisInputStream(in) default
return new RedisInputStream(in, size);
} Try / catch
try {
stream = new RedisInputStream(in, size);
} catch (IllegalArgumentException e) {
stream = new RedisInputStream(in); // default buffer
} Prevention
- Prefer the single-argument constructor to get the default buffer size.
- Validate configured buffer sizes at config load time (size > 0).
- Watch for computed sizes that can be zero after int arithmetic.
When it happens
Trigger: Constructing `new RedisInputStream(in, 0)` or with a negative size — e.g. a size computed from a config value, constant folding error, or an int overflow.
Common situations: Buffer size read from configuration where the value is 0/unset and cast to int without validation; misconfigured custom protocol clients.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/4ffb3325f075305a.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/util/RedisInputStream.java:39
/**
* This class assumes (to some degree) that we are reading a RESP stream. As such it assumes certain
* conventions regarding CRLF line termination. It also assumes that if the Protocol layer requires
* a byte that if that byte is not there it is a stream error.
*/
public class RedisInputStream extends FilterInputStream {
private static final int INPUT_BUFFER_SIZE = Integer.parseInt(
System.getProperty("jedis.bufferSize.input",
System.getProperty("jedis.bufferSize", "8192")));
protected final byte[] buf;
protected int count, limit;
public RedisInputStream(InputStream in, int size) {
super(in);
if (size <= 0) {
throw new IllegalArgumentException("Buffer size <= 0");
}
buf = new byte[size];
}
public RedisInputStream(InputStream in) {
this(in, INPUT_BUFFER_SIZE);
}
@Experimental
public boolean peek(byte b) throws JedisConnectionException {
ensureFill(); // in current design, at least one reply is expected. so ensureFillSafe() is not necessary.
return buf[count] == b;
}
public byte readByte() throws JedisConnectionException {
ensureFill();
return buf[count++];
}View on GitHub (pinned to 6dac31d4c2)