redis/jedis · error · InstantiationError
Must not instantiate this class
Error message
Must not instantiate this class
What it means
SearchBuilderFactory is a static-constants-only factory class; its private constructor throws InstantiationError to forbid instantiation. It only fires if code explicitly tries to construct the class.
Solutions
- Use the static builders directly, e.g. SearchBuilderFactory.SEARCH or SearchBuilderFactory.PROFILE
- Exclude utility/factory classes from reflective instantiation
- Delete any instantiation code
Example fix
// before SearchBuilderFactory f = new SearchBuilderFactory(); Builder b = f.SEARCH; // after Builder b = SearchBuilderFactory.SEARCH;
Defensive patterns
Strategy: type-guard
Prevention
- Use static builder fields directly; never construct factory classes
- Exclude factory/util classes from DI and reflection scanning
When it happens
Trigger: Writing new SearchBuilderFactory(); reflective instantiation by frameworks or Class.newInstance; accidental bean-scanning instantiation.
Common situations: Incorrect copy of factory-class usage; reflection-based tests or DI containers scanning and instantiating all classes in the package.
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
- Setting null as field attribute is not allowed.
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/7f03f4a1a9bfb9d6.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/search/SearchBuilderFactory.java:85
String header = STRING.build(rawElements.get(0));
if (!TERM.equals(header)) {
throw new IllegalStateException("Unrecognized header: " + header);
}
String term = STRING.build(rawElements.get(1));
List<List<Object>> list = (List<List<Object>>) rawElements.get(2);
Map<String, Double> entries = new LinkedHashMap<>(list.size());
list.forEach(entry -> entries.put(STRING.build(entry.get(1)), BuilderFactory.DOUBLE.build(entry.get(0))));
returnTerms.put(term, entries);
}
return returnTerms;
}
};
private SearchBuilderFactory() {
throw new InstantiationError("Must not instantiate this class");
}
}
View on GitHub (pinned to 6dac31d4c2)