{"record":{"id":"0c528ad40db050ef","repo":"redis/jedis","slug":"key-tostring-is-not-a-valid-argument-0c528a","errorCode":null,"errorMessage":"\" + key.toString() + \" is not a valid argument.","messagePattern":"\" \\+ key\\.toString\\(\\) \\+ \" is not a valid argument\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/util/PrefixedKeyArgumentPreProcessor.java","lineNumber":38,"sourceCode":"    this.prefixBytes = prefixBytes;\n  }\n\n  @Override\n  public Object actualKey(Object paramKey) {\n    return prefixKey(paramKey, prefixString, prefixBytes);\n  }\n\n  private static Object prefixKey(Object key, String prefixString, byte[] prefixBytes) {\n    if (key instanceof Rawable) {\n      byte[] raw = ((Rawable) key).getRaw();\n      return RawableFactory.from(prefixKeyWithBytes(raw, prefixBytes));\n    } else if (key instanceof byte[]) {\n      return prefixKeyWithBytes((byte[]) key, prefixBytes);\n    } else if (key instanceof String) {\n      String raw = (String) key;\n      return prefixString + raw;\n    }\n    throw new IllegalArgumentException(\"\\\"\" + key.toString() + \"\\\" is not a valid argument.\");\n  }\n\n  private static byte[] prefixKeyWithBytes(byte[] key, byte[] prefixBytes) {\n    byte[] namespaced = new byte[prefixBytes.length + key.length];\n    System.arraycopy(prefixBytes, 0, namespaced, 0, prefixBytes.length);\n    System.arraycopy(key, 0, namespaced, prefixBytes.length, key.length);\n    return namespaced;\n  }\n}\n","sourceCodeStart":20,"sourceCodeEnd":48,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/util/PrefixedKeyArgumentPreProcessor.java#L20-L48","documentation":"PrefixedKeyArgumentPreProcessor.prefixKey namespaces keys by prepending a prefix. It supports byte[] and String keys (via GSON JsonObject/JsonElement paths above); any other key type reaching it throws IllegalArgumentException(\"\\\"<key>\\\" is not a valid argument.\").","triggerScenarios":"Passing a key that is neither byte[] nor String (nor the supported JSON element types) to the prefixing pre-processor, e.g. a raw Long/UUID/custom object used as a Redis key with key-prefixing enabled.","commonSituations":"Passing numeric IDs or enum objects directly as keys instead of converting to String; custom key types after a version change of the API surface.","solutions":["Convert the key to String (or byte[]) before passing it, e.g. String.valueOf(id).","Check the accepted key types in prefixKey and normalize your key-building code to one of them.","If keys come from generic code, add a central toKey() helper that always produces String."],"exampleFix":"// before\nlong userId = 42;\ncommands.get(userId); // not a valid argument\n// after\ncommands.get(String.valueOf(userId));","handlingStrategy":"type-guard","validationCode":"static Object toKey(Object k) {\n  if (k instanceof String || k instanceof byte[]) return k;\n  return String.valueOf(k);\n}","typeGuard":"static boolean isValidPrefixedKey(Object k) {\n  return k instanceof String || k instanceof byte[];\n}","tryCatchPattern":null,"preventionTips":["Always pass String or byte[] keys.","Centralize key construction in one helper that stringifies IDs.","Never pass raw numeric/enum/custom objects as keys."],"tags":["key-prefixing","argument-type","validation"],"backgroundTag":"invalid-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"}