{"record":{"id":"d93bdbb11ea9e53b","repo":"redis/jedis","slug":"unknown-protocol","errorCode":null,"errorMessage":"Unknown protocol ","messagePattern":"Unknown protocol ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/util/JedisURIHelper.java","lineNumber":144,"sourceCode":"   *\n   * @param uri\n   * @return Redis protocol, or null if not specified\n   */\n  public static RedisProtocol getRedisProtocol(URI uri) {\n    if (uri.getQuery() == null) return null;\n\n    String[] params = uri.getQuery().split(\"&\");\n    for (String param : params) {\n      int idx = param.indexOf(\"=\");\n      if (idx < 0) continue;\n      if (\"protocol\".equals(param.substring(0, idx))) {\n        String ver = param.substring(idx + 1);\n        for (RedisProtocol proto : RedisProtocol.values()) {\n          if (proto.version().equals(ver)) {\n            return proto;\n          }\n        }\n        throw new IllegalArgumentException(\"Unknown protocol \" + ver);\n      }\n    }\n    return null; // null (default) when not defined\n  }\n\n  /**\n   * Validates that the given URI is a valid Redis URI.\n   * <p>\n   * A valid Redis URI must:\n   * <ul>\n   *   <li>Have a scheme of \"redis\" or \"rediss\" (case-insensitive)</li>\n   *   <li>Have a non-empty host</li>\n   *   <li>Have a valid port defined</li>\n   * </ul>\n   * <p>\n   *\n   * @param uri the URI to validate\n   * @return true if the URI is valid for Redis connections, false otherwise","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/util/JedisURIHelper.java#L126-L162","documentation":"getRedisProtocol(URI) reads a `protocol=` query parameter and matches its value against the known RedisProtocol enum versions. If the parameter value doesn't equal any enum's version string, the library throws IllegalArgumentException(\"Unknown protocol ...\"). Missing parameter returns null (default).","triggerScenarios":"A URI whose query string contains protocol=<value> where <value> is not a valid RedisProtocol version, e.g. `redis://host:6379/?protocol=3` or `?protocol=resp2` when only values like `2`/`3` matching RedisProtocol.version() are accepted.","commonSituations":"Guessing the parameter format (name-based 'resp3' vs version-based); copying URIs from other clients (e.g. node-redis uses different protocol syntax); typos or whitespace in the query value.","solutions":["Use the exact version string matching RedisProtocol.values()[i].version(), e.g. `?protocol=3` for RESP3.","Print the valid values from RedisProtocol.values() to see accepted strings before crafting the URI.","Drop the protocol parameter entirely if you want the default (RESP2) and configure the protocol programmatically via RedisProtocol in the client config instead."],"exampleFix":"// before\nURI uri = URI.create(\"redis://localhost:6379/?protocol=resp3\"); // throws\n// after\nURI uri = URI.create(\"redis://localhost:6379/?protocol=3\");","handlingStrategy":"validation","validationCode":"static boolean hasKnownProtocol(URI uri) {\n  String q = uri.getQuery();\n  if (q == null) return true;\n  for (String p : q.split(\"&\")) {\n    if (p.startsWith(\"protocol=\")) {\n      String v = p.substring(\"protocol=\".length());\n      for (RedisProtocol rp : RedisProtocol.values()) {\n        if (rp.version().equals(v)) return true;\n      }\n      return false;\n    }\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  RedisProtocol p = JedisURIHelper.getRedisProtocol(uri);\n} catch (IllegalArgumentException e) {\n  // fall back to default protocol (null)\n}","preventionTips":["Copy protocol values from RedisProtocol.version() strings, not other clients' syntax.","Trim query parameter values when constructing URIs programmatically."],"tags":["uri","protocol","enum","argument-value"],"backgroundTag":"invalid-enum-value","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"}