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
- Call the static methods directly, e.g. Values.gt(10) or Values.tags("a","b"), instead of constructing Values.
- Exclude utility classes from reflective instantiation lists in your tooling configuration.
- 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
- Use Values.gt/eq/tags static factories instead of constructing the class.
- Skip utility classes in reflection-based instantiation sweeps.
- Document utility classes as non-instantiable in team coding guidelines.
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
- Must not instantiate this class
- Must not instantiate this class
- DIALECT=0 cannot be set.
- Must have at least one tag
- All required VectorField parameters are not set.
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)