redis/jedis · error · InstantiationError
Must not instantiate this class
Error message
Must not instantiate this class
What it means
BuilderFactory is a utility class of static Builder constants for converting Redis replies into Java types. Its constructor is private and deliberately throws InstantiationError to prevent instantiation, since all functionality is exposed via static fields. This error means you (or reflection/serialization code) tried to create a new BuilderFactory instance.
Solutions
- Remove the `new BuilderFactory()` call and use the static Builder constants directly, e.g. `BuilderFactory.STRING`
- If a framework needs to instantiate it, register it as non-instantiable or exclude it from reflective instantiation
- If you need custom reply building, implement redis.clients.jedis.Builder yourself rather than subclassing/instantiating BuilderFactory
Example fix
// before BuilderFactory factory = new BuilderFactory(); Object val = factory.build(data); // after Object val = BuilderFactory.STRING.build(data);
Defensive patterns
Strategy: validation
Validate before calling
if (factory == null || factory.getClass() == BuilderFactory.class) { /* use static constants instead of instantiating */ } Type guard
static boolean isBuilderFactoryConstant(Object o) { return o instanceof redis.clients.jedis.Builder; } Try / catch
try { new BuilderFactory(); } catch (InstantiationError e) { logger.warn("BuilderFactory is a static utility class; use its Builder constants"); } Prevention
- Never instantiate *Factory/*Builders utility classes with private constructors; use their static members
- Exclude utility classes from reflection-based instantiation and code-coverage constructor tests
- Prefer implementing the Builder interface for custom reply building
When it happens
Trigger: Calling `new BuilderFactory()` from user code, or frameworks that instantiate classes via reflection (e.g. some serializers, DI containers, or code-coverage tooling instantiating classes with private constructors).
Common situations: Accidental autocomplete-driven instantiation of a constants-only utility class; reflection-based tests requiring a constructor; serialization libraries attempting to deserialize BuilderFactory.
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
- Must not instantiate this class
- Must not instantiate this class
- Must not instantiate this class
- Must not instantiate this class
- Must not instantiate this class
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/ef9ec06151cc0570.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/BuilderFactory.java:2638
final List<Object> list = (List<Object>) data;
if (list.isEmpty()) return Collections.emptyList();
final List<KeyValue<Long, byte[]>> result = new ArrayList<>(list.size());
for (Object pair : list) {
List<Object> entry = (List<Object>) pair;
result.add(KeyValue.of(LONG.build(entry.get(0)), BINARY.build(entry.get(1))));
}
return result;
}
@Override
public String toString() {
return "List<KeyValue<Long, byte[]>>";
}
};
private BuilderFactory() {
throw new InstantiationError("Must not instantiate this class");
}
}
View on GitHub (pinned to 6dac31d4c2)