{"record":{"id":"517a154279f0b2fa","repo":"redis/jedis","slug":"must-not-instantiate-this-class-517a15","errorCode":null,"errorMessage":"Must not instantiate this class","messagePattern":"Must not instantiate this class","errorType":"exception","errorClass":"InstantiationError","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/search/RediSearchUtil.java","lineNumber":114,"sourceCode":"    char[] chars = text.toCharArray();\n\n    StringBuilder sb = new StringBuilder();\n    for (char ch : chars) {\n      if (ESCAPE_CHARS.contains(ch)\n          || (querying && ch == ' ')) {\n        sb.append(\"\\\\\");\n      }\n      sb.append(ch);\n    }\n    return sb.toString();\n  }\n\n  public static String unescape(String text) {\n    return text.replace(\"\\\\\", \"\");\n  }\n\n  private RediSearchUtil() {\n    throw new InstantiationError(\"Must not instantiate this class\");\n  }\n}\n","sourceCodeStart":96,"sourceCodeEnd":117,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/search/RediSearchUtil.java#L96-L117","documentation":"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().","triggerScenarios":"Writing new RediSearchUtil(); invoking the constructor reflectively (e.g. frameworks instantiating classes); serialization/deserialization libraries attempting to construct it.","commonSituations":"Copying utility-class patterns incorrectly; reflection-based bean instantiation or Class.newInstance scanning the package.","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"],"exampleFix":"// before\nRediSearchUtil util = new RediSearchUtil();\nString escaped = util.escape(text);\n// after\nString escaped = RediSearchUtil.escape(text);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never instantiate utility classes — call their static methods","Configure reflection/bean scanners to skip *Util classes"],"tags":["redisearch","utility-class","instantiation"],"backgroundTag":"unsupported-operation","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}