languagetool-org/languagetool · error · RuntimeException
Constructor of filter class '${className}' must have exactly
Error message
Constructor of filter class '${className}' must have exactly one constructor, but it has ${constructors.length} What it means
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.
Source
Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/RegexRuleFilterCreator.java:39
import org.languagetool.JLanguageTool;
import java.lang.reflect.Constructor;
/**
* Create a {@link RegexRuleFilter}.
* @since 5.2
*/
public class RegexRuleFilterCreator {
/**
* @param className fully qualified class Name of a class implementing {@link RegexRuleFilter}
*/
public RegexRuleFilter getFilter(String className) {
try {
Class<?> aClass = JLanguageTool.getClassBroker().forName(className);
Constructor<?>[] constructors = aClass.getConstructors();
if (constructors.length != 1) {
throw new RuntimeException("Constructor of filter class '"
+ className + "' must have exactly one constructor, but it has " + constructors.length);
}
Constructor<?> constructor = constructors[0];
try {
if (constructor.getParameterTypes().length != 0) {
throw new RuntimeException("Constructor of filter class '" + className + "' must not have arguments: " + constructor);
}
Object filter = constructor.newInstance();
if (filter instanceof RegexRuleFilter) {
return (RegexRuleFilter) filter;
} else {
throw new RuntimeException("Filter class '" + className + "' must implement interface " + RegexRuleFilter.class.getSimpleName());
}
} catch (Exception e) {
throw new RuntimeException("Could not create filter class using constructor " + constructor, e);
}
} catch (ClassNotFoundException e) {
throw new RuntimeException("Could not find filter class: '"View on GitHub (pinned to 2e990059ce)
Solutions
- Give the filter class exactly one public constructor (an implicit default constructor counts)
- Remove extra overloaded constructors from the filter class
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/RegexRuleFilterCreator.java:39 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/a4f7ec89fbc9a1a8.
Report an issue: GitHub.