{"record":{"id":"6c0428d134c7599d","repo":"redis/jedis","slug":"null-is-not-a-valid-argument","errorCode":null,"errorMessage":"null is not a valid argument.","messagePattern":"null is not a valid argument\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/CommandArguments.java","lineNumber":91,"sourceCode":"  public CommandArguments add(int arg) {\n    return add(RawableFactory.from(arg));\n  }\n\n  public CommandArguments add(long arg) {\n    return add(RawableFactory.from(arg));\n  }\n\n  public CommandArguments add(double arg) {\n    return add(RawableFactory.from(arg));\n  }\n\n  public CommandArguments add(String arg) {\n    return add(RawableFactory.from(arg));\n  }\n\n  public CommandArguments add(Object arg) {\n    if (arg == null) {\n      throw new IllegalArgumentException(\"null is not a valid argument.\");\n    } else if (arg instanceof Rawable) {\n      args.add((Rawable) arg);\n    } else if (arg instanceof byte[]) {\n      args.add(RawableFactory.from((byte[]) arg));\n    } else if (arg instanceof Boolean) {\n      args.add(RawableFactory.from((Boolean) arg));\n    } else if (arg instanceof Integer) {\n      args.add(RawableFactory.from((Integer) arg));\n    } else if (arg instanceof Long) {\n      args.add(RawableFactory.from((Long) arg));\n    } else if (arg instanceof Double) {\n      args.add(RawableFactory.from((Double) arg));\n    } else if (arg instanceof float[]) {\n      args.add(RawableFactory.from(RediSearchUtil.toByteArray((float[]) arg)));\n    } else if (arg instanceof String) {\n      args.add(RawableFactory.from((String) arg));\n    } else if (arg instanceof GeoCoordinate) {\n      GeoCoordinate geo = (GeoCoordinate) arg;","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/CommandArguments.java#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\njedis.set(key, value); // value may be null\n// after\nif (value != null) {\n  jedis.set(key, value);\n}","handlingStrategy":"validation","validationCode":"static void requireNonNullArgs(Object... args) {\n  for (int i = 0; i < args.length; i++)\n    if (args[i] == null)\n      throw new IllegalArgumentException(\"Command argument at index \" + i + \" is null\");\n}","typeGuard":"static <T> T nonNull(T v, String name) {\n  if (v == null) throw new IllegalArgumentException(name + \" must not be null\");\n  return v;\n}","tryCatchPattern":"try {\n  jedis.set(key, value);\n} catch (IllegalArgumentException e) {\n  if (\"null is not a valid argument.\".equals(e.getMessage())) {\n    // skip command or apply default\n  } else throw e;\n}","preventionTips":["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."],"tags":["null-check","invalid-argument","redis"],"backgroundTag":"null-argument","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}