redis/jedis · error · InstantiationError

Must not instantiate this class

Error message

Must not instantiate this class

What it means

Values is a static utility class for building RediSearch filter Values (numeric ranges, tags). Its private constructor throws java.lang.InstantiationError to signal that the class must never be instantiated; it only exposes static factory methods such as Values.gt, Values.eq, Values.tags.

Solutions

  1. Call the static methods directly, e.g. Values.gt(10) or Values.tags("a","b"), instead of constructing Values.
  2. Exclude utility classes from reflective instantiation lists in your tooling configuration.
  3. Wrap needed helpers in your own class if you require an object-oriented handle.

Example fix

// before
Values v = new Values(); // InstantiationError
// after
Value v = Values.between(1, 10); // static factory
Defensive patterns

Strategy: try-catch

Validate before calling

if (clazz == Values.class) {
  throw new IllegalStateException("Values is a utility class; use its static methods");
}

Type guard

boolean isUtilityClass(Class<?> c) {
  return c == Values.class;
}

Try / catch

try {
  ctor.setAccessible(true);
  ctor.newInstance();
} catch (java.lang.InstantiationError e) {
  log.warn("Values must not be instantiated; use static factories like Values.gt()");
}

Prevention

When it happens

Trigger: Instantiating the class through reflection (Constructor.newInstance on the private constructor), code generation, or tooling that constructs every class in the package; direct instantiation is a compile error.

Common situations: Coverage or mocking frameworks instantiating utility classes for completeness; reflection-driven plugins; copy-pasted code that attempts `new Values()` in dynamically compiled snippets.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at src/main/java/redis/clients/jedis/search/querybuilder/Values.java:13

package redis.clients.jedis.search.querybuilder;

import redis.clients.jedis.GeoCoordinate;
import redis.clients.jedis.args.GeoUnit;

import java.util.StringJoiner;

/**
 * Created by mnunberg on 2/23/18.
 */
public class Values {
  private Values() {
    throw new InstantiationError("Must not instantiate this class");
  }

  private abstract static class ScalableValue extends Value {
    @Override
    public boolean isCombinable() {
      return true;
    }
  }

  public static Value value(String s) {
    return new ScalableValue() {
      @Override
      public String toString() {
        return s;
      }
    };
  }

View on GitHub (pinned to 6dac31d4c2)