{"record":{"id":"a4f7ec89fbc9a1a8","repo":"languagetool-org/languagetool","slug":"constructor-of-filter-class-classname-must-ha","errorCode":null,"errorMessage":"Constructor of filter class '${className}' must have exactly one constructor, but it has ${constructors.length}","messagePattern":"Constructor of filter class '(.+?)' must have exactly one constructor, but it has (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/rules/patterns/RegexRuleFilterCreator.java","lineNumber":39,"sourceCode":"import org.languagetool.JLanguageTool;\n\nimport java.lang.reflect.Constructor;\n\n/**\n * Create a {@link RegexRuleFilter}.\n * @since 5.2\n */\npublic class RegexRuleFilterCreator {\n\n  /**\n   * @param className fully qualified class Name of a class implementing {@link RegexRuleFilter}\n   */\n  public RegexRuleFilter getFilter(String className) {\n    try {\n      Class<?> aClass = JLanguageTool.getClassBroker().forName(className);\n      Constructor<?>[] constructors = aClass.getConstructors();\n      if (constructors.length != 1) {\n        throw new RuntimeException(\"Constructor of filter class '\"\n                + className + \"' must have exactly one constructor, but it has \" + constructors.length);\n      }\n      Constructor<?> constructor = constructors[0];\n      try {\n        if (constructor.getParameterTypes().length != 0) {\n          throw new RuntimeException(\"Constructor of filter class '\" + className + \"' must not have arguments: \" + constructor);\n        }\n        Object filter = constructor.newInstance();\n        if (filter instanceof RegexRuleFilter) {\n          return (RegexRuleFilter) filter;\n        } else {\n          throw new RuntimeException(\"Filter class '\" + className + \"' must implement interface \" + RegexRuleFilter.class.getSimpleName());\n        }\n      } catch (Exception e) {\n        throw new RuntimeException(\"Could not create filter class using constructor \" + constructor, e);\n      }\n    } catch (ClassNotFoundException e) {\n      throw new RuntimeException(\"Could not find filter class: '\"","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/rules/patterns/RegexRuleFilterCreator.java#L21-L57","documentation":"Reflection-based setup check in RegexRuleFilterCreator.getFilter: the filter class named in an XML rule was loaded, but reflection found more or fewer than exactly one public constructor, so the creator cannot decide how to instantiate it. The input at fault is the class referenced by the <filter class=\"...\"> attribute.","triggerScenarios":"Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/RegexRuleFilterCreator.java:39 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Give the filter class exactly one public constructor (an implicit default constructor counts)","Remove extra overloaded constructors from the filter class"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}