redis/jedis · error · InstantiationError
Must not instantiate this class
Error message
Must not instantiate this class
What it means
RediSearchUtil is a static-only utility class; its private constructor deliberately throws InstantiationError to prevent instantiation. It is not meant to be thrown at call sites — it only fires if you (or reflection) try to new RediSearchUtil().
Solutions
- Use the static methods directly: RediSearchUtil.toStringMap(...) / RediSearchUtil.escape(...) / unescape(...)
- Exclude the class from reflection-based instantiation scans
- Remove any code that instantiates utility classes
Example fix
// before RediSearchUtil util = new RediSearchUtil(); String escaped = util.escape(text); // after String escaped = RediSearchUtil.escape(text);
Defensive patterns
Strategy: type-guard
Prevention
- Never instantiate utility classes — call their static methods
- Configure reflection/bean scanners to skip *Util classes
When it happens
Trigger: Writing new RediSearchUtil(); invoking the constructor reflectively (e.g. frameworks instantiating classes); serialization/deserialization libraries attempting to construct it.
Common situations: Copying utility-class patterns incorrectly; reflection-based bean instantiation or Class.newInstance scanning 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/517a154279f0b2fa.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/search/RediSearchUtil.java:114
char[] chars = text.toCharArray();
StringBuilder sb = new StringBuilder();
for (char ch : chars) {
if (ESCAPE_CHARS.contains(ch)
|| (querying && ch == ' ')) {
sb.append("\\");
}
sb.append(ch);
}
return sb.toString();
}
public static String unescape(String text) {
return text.replace("\\", "");
}
private RediSearchUtil() {
throw new InstantiationError("Must not instantiate this class");
}
}
View on GitHub (pinned to 6dac31d4c2)