{"record":{"id":"acf326e6b80cc2e7","repo":"redis/jedis","slug":"password-not-provided-in-uri","errorCode":null,"errorMessage":"Password not provided in uri.","messagePattern":"Password not provided in uri\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/util/JedisURIHelper.java","lineNumber":82,"sourceCode":"    return null;\n  }\n\n  /**\n   * Extracts the password from the given URI.\n   * <p>\n   * For details on the URI format and authentication examples, see {@link JedisURIHelper}.\n   * </p>\n   * @param uri the URI to extract the password from\n   * @return the password as a String, or null if {@link URI#getUserInfo()} info is missing\n   * @throws IllegalArgumentException if {@link URI#getUserInfo()} is provided but does not contain\n   *           a password\n   */\n  public static String getPassword(URI uri) {\n    String userInfo = uri.getUserInfo();\n    if (userInfo != null) {\n      String[] userAndPassword = userInfo.split(\":\", 2);\n      if (userAndPassword.length < 2) {\n        throw new IllegalArgumentException(\"Password not provided in uri.\");\n      }\n      return userAndPassword[1];\n    }\n    return null;\n  }\n\n  /**\n   * Checks if the given URI has a database index component.\n   *\n   * @param uri the URI to check\n   * @return true if the URI has a database index component, false otherwise\n   */\n  public static boolean hasDbIndex(URI uri) {\n    if (uri.getPath() == null || uri.getPath().isEmpty()) {\n      return false;\n    }\n\n    String[] pathSplit = uri.getPath().split(\"/\", 2);","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/util/JedisURIHelper.java#L64-L100","documentation":"getPassword(URI) parses the URI's userInfo and expects the form `password` or `user:password`. When userInfo exists but contains no ':' separator (after splitting with limit 2), the library concludes no password portion was provided and throws IllegalArgumentException. A URI with no userInfo at all returns null instead.","triggerScenarios":"Passing a URI like `redis://mypassword@host:6379/` (bare token with no colon) to getPassword. Any single-segment userInfo — `redis://user@host`, `redis://token@host` — triggers it, since split(\":\", 2) yields length 1.","commonSituations":"Copying connection URIs from providers that URL-encode only the username; ACL-enabled Redis setups where people assume `redis://default@host` carries the password; hand-written URIs missing the `user:password` form.","solutions":["Rewrite the URI userInfo to include the password after a colon: `redis://default:YOURPASS@host:6379/`.","URL-encode special characters in both user and password (e.g. '@' -> %40) so splitting on ':' works as expected.","If your URI genuinely has no password, don't call getPassword — handle the null case from a null userInfo instead, or use JedisClientConfig setters."],"exampleFix":"// before\nURI uri = URI.create(\"redis://secretpass@localhost:6379/2\");\nString pass = JedisURIHelper.getPassword(uri); // throws\n// after\nURI uri = URI.create(\"redis://default:secretpass@localhost:6379/2\");\nString pass = JedisURIHelper.getPassword(uri);","handlingStrategy":"validation","validationCode":"static boolean uriHasPassword(URI uri) {\n  String ui = uri.getUserInfo();\n  return ui != null && ui.contains(\":\");\n}\n// call before JedisURIHelper.getPassword(uri)","typeGuard":null,"tryCatchPattern":"try {\n  String pass = JedisURIHelper.getPassword(uri);\n} catch (IllegalArgumentException e) {\n  // prompt/rebuild URI with user:password form\n}","preventionTips":["Always build redis URIs as redis://user:password@host:port/db.","URL-encode ':' and '@' inside credentials with URLEncoder.","Validate the userInfo shape before parsing."],"tags":["uri","password","authentication","argument-format"],"backgroundTag":"missing-credentials","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"}