redis/jedis · error · IllegalArgumentException
null is not a valid argument.
Error message
null is not a valid argument.
What it means
CommandArguments.add(Object) validates every command argument and rejects null immediately with an IllegalArgumentException. Redis commands cannot contain null arguments, so the client fails fast instead of sending a malformed command to the server.
Solutions
- Null-check every argument before calling the command and skip the call or substitute a default value when null.
- Use Optional.ofNullable(value).ifPresent(v -> jedis.set(key, v)) to make the intent explicit.
- Trace where the null comes from (often a failed Map/lookup or unset config) and fix the upstream data source.
Example fix
// before
jedis.set(key, value); // value may be null
// after
if (value != null) {
jedis.set(key, value);
} Defensive patterns
Strategy: validation
Validate before calling
static void requireNonNullArgs(Object... args) {
for (int i = 0; i < args.length; i++)
if (args[i] == null)
throw new IllegalArgumentException("Command argument at index " + i + " is null");
} Type guard
static <T> T nonNull(T v, String name) {
if (v == null) throw new IllegalArgumentException(name + " must not be null");
return v;
} Try / catch
try {
jedis.set(key, value);
} catch (IllegalArgumentException e) {
if ("null is not a valid argument.".equals(e.getMessage())) {
// skip command or apply default
} else throw e;
} Prevention
- Null-check values before building any Redis command.
- Use Optional to express potentially-absent values and skip the command when empty.
- Never feed Map.get() or config lookups directly into command calls.
When it happens
Trigger: Passing a null argument to any command builder, e.g. set(key, null), an Optional.get() that resolved to null, a Map.get(key) that returned null used as a command value, or a builder method forwarding a null varargs element.
Common situations: A config value or cache lookup returned null and was fed straight into a command; conditional logic that skips setting a variable ended up passing null; deserialized objects with missing fields used as command values.
Related errors
- Stream entry deletion result value cannot be null
- DriverInfo must not be null
- Unsupported key type
- " " is not a valid argument.
- protocol must not be null
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/6c0428d134c7599d.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/CommandArguments.java:91
public CommandArguments add(int arg) {
return add(RawableFactory.from(arg));
}
public CommandArguments add(long arg) {
return add(RawableFactory.from(arg));
}
public CommandArguments add(double arg) {
return add(RawableFactory.from(arg));
}
public CommandArguments add(String arg) {
return add(RawableFactory.from(arg));
}
public CommandArguments add(Object arg) {
if (arg == null) {
throw new IllegalArgumentException("null is not a valid argument.");
} else if (arg instanceof Rawable) {
args.add((Rawable) arg);
} else if (arg instanceof byte[]) {
args.add(RawableFactory.from((byte[]) arg));
} else if (arg instanceof Boolean) {
args.add(RawableFactory.from((Boolean) arg));
} else if (arg instanceof Integer) {
args.add(RawableFactory.from((Integer) arg));
} else if (arg instanceof Long) {
args.add(RawableFactory.from((Long) arg));
} else if (arg instanceof Double) {
args.add(RawableFactory.from((Double) arg));
} else if (arg instanceof float[]) {
args.add(RawableFactory.from(RediSearchUtil.toByteArray((float[]) arg)));
} else if (arg instanceof String) {
args.add(RawableFactory.from((String) arg));
} else if (arg instanceof GeoCoordinate) {
GeoCoordinate geo = (GeoCoordinate) arg;View on GitHub (pinned to 6dac31d4c2)