Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: JedisURIHelper.getPassword - java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1 #4003

Open
Links2004 opened this issue Oct 25, 2024 · 3 comments

Comments

@Links2004
Copy link

Links2004 commented Oct 25, 2024

Expected behavior

JedisURIHelper.getPassword does return null when there is only a username and no password in the URI.

Actual behavior

JedisURIHelper.getPassword does throw a exception when there is only a username and no password in the URI.

java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
	at redis.clients.jedis.util.JedisURIHelper.getPassword(JedisURIHelper.java:36)

Steps to reproduce:

URI redisProperUri = URI.create("redis://user@redisHost.redisDomain");
JedisURIHelper.getPassword(redisProperUri); 

Redis / Jedis Configuration

Jedis version:

Redis version:

Java version:

@sazzad16
Copy link
Collaborator

Redis has two authentication options:

  1. password only - legacy AUTH mode
  2. username and password - updated AUTH mode

There is no username only mode. As a client for Redis, what should Jedis do in such case?

@Links2004
Copy link
Author

Links2004 commented Oct 28, 2024

reporting a AUTH error is good,
having a stack trace that you do not understand with out reading the code is bad.

or be more spezifisch return null for the getPassword function and not a ArrayIndexOutOfBoundsException

public static String getPassword(URI uri) {
String userInfo = uri.getUserInfo();
if (userInfo != null) {
return userInfo.split(":", 2)[1];
}
return null;
}

this is about handling wrong user Input/Configuration (like you stated if there is a username there must be a password).
failing the AUTH is totally expected, but having a stack trace with ArrayIndexOutOfBoundsException is hard to understand.

@sazzad16
Copy link
Collaborator

@Links2004 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants