languagetool-org/languagetool · error · IllegalArgumentException

suppressMisspelledSuggestions must be a valid regex

Error message

suppressMisspelledSuggestions must be a valid regex

What it means

Same family as error 56 but for the optional RemoteRule option 'suppressMisspelledSuggestions': the constructor compiles its value into a Pattern, and an invalid regex is rethrown as IllegalArgumentException with this message.

Source

Thrown at languagetool-core/src/main/java/org/languagetool/rules/RemoteRule.java:100

    boolean includedInHiddenMatches = Boolean.parseBoolean(serviceConfiguration.getOptions().getOrDefault("includedInHiddenMatches", "true"));
    setIncludedInHiddenMatches(includedInHiddenMatches);
    try {
      if (serviceConfiguration.getOptions().containsKey("suppressMisspelledMatch")) {
        suppressMisspelledMatch = Pattern.compile(serviceConfiguration.getOptions().get("suppressMisspelledMatch"));
      } else {
        suppressMisspelledMatch = null;
      }
    } catch(PatternSyntaxException e) {
      throw new IllegalArgumentException("suppressMisspelledMatch must be a valid regex", e);
    }
    try {
      if (serviceConfiguration.getOptions().containsKey("suppressMisspelledSuggestions")) {
        suppressMisspelledSuggestions = Pattern.compile(serviceConfiguration.getOptions().get("suppressMisspelledSuggestions"));
      } else {
        suppressMisspelledSuggestions = null;
      }
    } catch(PatternSyntaxException e) {
      throw new IllegalArgumentException("suppressMisspelledSuggestions must be a valid regex", e);
    }
  }

  public RemoteRule(Language language, ResourceBundle messages, RemoteRuleConfig config, boolean inputLogging) {
    this(language, messages, config, inputLogging, null);
  }

  public static void shutdown() {
    shutdownRoutines.forEach(Runnable::run);
  }

  public FutureTask<RemoteRuleResult> run(List<AnalyzedSentence> sentences) {
    return run(sentences, null);
  }

  protected static class RemoteRequest {}

  /**

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Correct the suppressMisspelledSuggestions option value so it compiles as a Java regex.
  2. Validate the pattern with Pattern.compile before loading config.
  3. Drop the option if it's not needed — it's optional.
  4. Double-check backslash escaping in the config file format.

Example fix

// before
suppressMisspelledSuggestions=[misspelled
// after
suppressMisspelledSuggestions=(misspelled|mistyped)
Defensive patterns

Strategy: try-catch

Validate before calling

String opt = serviceConfig.getOptions().get("suppressMisspelledSuggestions");
if (opt != null) {
  try { java.util.regex.Pattern.compile(opt); }
  catch (java.util.regex.PatternSyntaxException e) {
    throw new IllegalArgumentException("suppressMisspelledSuggestions is not valid regex: " + e.getMessage());
  }
}

Try / catch

try {
  rule = new RemoteRule(language, messages, config, inputLogging);
} catch (IllegalArgumentException e) {
  LOG.error("Bad suppressMisspelledSuggestions regex: {}", e.getMessage());
  throw e;
}

Prevention

When it happens

Trigger: Setting RemoteRuleConfig option suppressMisspelledSuggestions to a string that Pattern.compile() rejects (syntax error such as unmatched '[', trailing '\', or '+' with no operand).

Common situations: Copy-pasting grep-flavored regex into Java config, mis-escaping in properties/JSON layers, or generating the option value dynamically from user input without validation.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/231fdfdd2abb9c59. Report an issue: GitHub.