{"record":{"id":"a95e65643ad29761","repo":"redis/jedis","slug":"key-getclass-getsimplename-is-not-supported","errorCode":null,"errorMessage":"${key.getClass().getSimpleName()} is not supported. Value: \"${String.valueOf(key)}\".","messagePattern":"(.+?) is not supported\\. Value: \"(.+?)\"\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/csc/AbstractCache.java","lineNumber":251,"sourceCode":"   * <p>\n   * This normalization ensures that:\n   * <ul>\n   *   <li>String key {@code \"user:1\"} and byte key {@code byte[]{0x75, 0x73, 0x65, 0x72, 0x3a, 0x31}} are treated as equal</li>\n   *   <li>Cache invalidation works correctly regardless of whether keys were added as String or byte[]</li>\n   *   <li>Type mismatches are caught early with clear error messages</li>\n   * </ul>\n   *\n   * @param key the Redis key (must be {@link String} or {@code byte[]})\n   * @return ByteBuffer wrapping the normalized byte representation\n   * @throws IllegalArgumentException if key is not {@link String} or {@code byte[]}\n   */\n  private ByteBuffer makeKeyForRedisKeysToCacheKeys(Object key) {\n    if (key instanceof byte[]) {\n      return makeKeyForRedisKeysToCacheKeys((byte[]) key);\n    } else if (key instanceof String) {\n      return makeKeyForRedisKeysToCacheKeys(SafeEncoder.encode((String) key));\n    } else {\n      throw new IllegalArgumentException(key.getClass().getSimpleName() + \" is not supported.\"\n          + \" Value: \\\"\" + String.valueOf(key) + \"\\\".\");\n    }\n  }\n\n  /**\n   * Wraps a byte array in a ByteBuffer for use as a map key.\n   * <p>\n   * ByteBuffer provides content-based equality, which is required for proper map key behavior\n   * with byte arrays.\n   *\n   * @param b the byte array to wrap\n   * @return ByteBuffer wrapping the byte array\n   */\n  private static ByteBuffer makeKeyForRedisKeysToCacheKeys(byte[] b) {\n    return ByteBuffer.wrap(b);\n  }\n\n}","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/csc/AbstractCache.java#L233-L269","documentation":"Client-side caching keys must be byte[] or String Redis keys; AbstractCache.makeKeyForRedisKeysToCacheKeys() normalizes them into BufferedKey ByteBuffers for the internal map. Any other key type (e.g. Integer, long-wrapped objects, custom key classes) hits the else branch and throws this IllegalArgumentException naming the key's simple class and its string value.","triggerScenarios":"Passing a non-String/non-byte[] key object into cache-facing operations or direct cache access paths that route through mapKey/makeKeyForRedisKeysToCacheKeys (e.g. using Integer or a custom Key type where String keys are expected).","commonSituations":"Auto-unboxed numeric keys from generic DAO code; custom wrapper key classes passed instead of their toString()/value; mixing a cache API keyed by byte[] with application-level typed keys.","solutions":["Convert the key to a String (or byte[]) before using it with the cache, e.g. String.valueOf(key) or SafeEncoder.encode(key.toString()).","If using a custom key class, extract its underlying String/byte[] representation at the call site.","Add a guard in your data-access layer enforcing that cache keys are always String or byte[]."],"exampleFix":"// before\ncache.getKey(12345); // IllegalArgumentException: Integer is not supported\n// after\ncache.getKey(String.valueOf(12345));","handlingStrategy":"type-guard","validationCode":"if (!(key instanceof String) && !(key instanceof byte[])) {\n  throw new IllegalArgumentException(\"cache keys must be String or byte[]: \" + key.getClass());\n}","typeGuard":"static ByteBuffer toCacheKey(Object key) {\n  if (key instanceof byte[]) return ByteBuffer.wrap((byte[]) key);\n  if (key instanceof String) return ByteBuffer.wrap(SafeEncoder.encode((String) key));\n  throw new IllegalArgumentException(\"Unsupported cache key type: \" + key.getClass());\n}","tryCatchPattern":"try {\n  cache.getKey(rawKey);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().endsWith(\"is not supported.\")) {\n    cache.getKey(String.valueOf(rawKey));\n  } else {\n    throw e;\n  }\n}","preventionTips":["Standardize cache keys as String (or byte[]) in a shared key-builder utility.","Avoid passing boxed numerics or custom key wrappers into cache APIs.","Use SafeEncoder.encode() for String-to-bytes conversion to preserve encoding semantics."],"tags":["jedis","client-side-caching","cache","type-mismatch","argument"],"backgroundTag":"type-mismatch","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"}