redis/jedis · error · InstantiationError

Must not instantiate this class

Error message

Must not instantiate this class

What it means

JedisURIHelper is a final utility class with only static helpers (URI parsing for redis/rediss URIs). Its private constructor deliberately throws InstantiationError to signal that instantiation is a programming mistake. The library forbids instances so callers must use the static methods directly.

Solutions

  1. Remove the instantiation and call the static methods directly, e.g. JedisURIHelper.getHostAndPort(uri).
  2. If you wrapped the class, make your wrapper's methods static too.
  3. Check import/IDE quick-fixes that inserted `new JedisURIHelper()` and delete it.

Example fix

// before
JedisURIHelper helper = new JedisURIHelper();
HostAndPort hp = helper.getHostAndPort(uri);
// after
HostAndPort hp = JedisURIHelper.getHostAndPort(uri);
Defensive patterns

Strategy: validation

Validate before calling

// Never instantiate; assert you only reference static methods.
HostAndPort hp = JedisURIHelper.getHostAndPort(uri);

Prevention

When it happens

Trigger: Calling `new JedisURIHelper()` — the only way to trigger it, since all public members are static and the class is final.

Common situations: Developers used to non-static utility APIs instantiate the class before calling getHostAndPort/getPassword/getRedisProtocol; IDE auto-complete or refactoring tools may generate an instance unnecessarily.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/16055ae7b4286be2. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/util/JedisURIHelper.java:40

 * <h2>Authentication</h2>
 * <p>Authentication details can be provided in the URI in the form of a username and password.
 * Redis URIs may contain authentication details that effectively lead to usernames with passwords,
 * password-only, or no authentication.</p>
 * <h3>Examples:</h3>
 * <ul>
 *   <li><b>Username and Password:</b> redis://username:password@host:port</li>
 *   <li><b>Password-only:</b> redis://:password@host:port</li>
 *   <li><b>Empty password:</b> redis://username:@host:port</li>
 *   <li><b>No Authentication:</b> redis://host:port</li>
 * </ul>
 */
public final class JedisURIHelper {

  private static final String REDIS = "redis";
  private static final String REDISS = "rediss";

  private JedisURIHelper() {
    throw new InstantiationError("Must not instantiate this class");
  }

  public static HostAndPort getHostAndPort(URI uri) {
    return new HostAndPort(uri.getHost(), uri.getPort());
  }

  /**
   * Extracts the user from the given URI.
   * <p>
   * For details on the URI format and authentication examples, see {@link JedisURIHelper}.
   * </p>
   * @param uri the URI to extract the user from
   * @return the user as a String, or null if user is empty or {@link URI#getUserInfo()} info is missing
   */
  public static String getUser(URI uri) {
    String userInfo = uri.getUserInfo();
    if (userInfo != null) {
      String user = userInfo.split(":", 2)[0];

View on GitHub (pinned to 6dac31d4c2)