languagetool-org/languagetool · error · IllegalArgumentException

You cannot specify both disabled rules and enabledonly

Error message

You cannot specify both disabled rules and enabledonly

What it means

`-eo/--enabledonly` restricts checking to explicitly enabled rules, so it is incompatible with -d/--disable. When --enabledonly is parsed and the disabled-rules list is non-empty, parseOptions() throws IllegalArgumentException.

Source

Thrown at languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java:77

          options.setLevel(JLanguageTool.Level.valueOf(level));
        } catch (IllegalArgumentException e) {
          throw new IllegalArgumentException("Unknown level '" + level + "' - currently, only 'PICKY' is supported");
        }
      } else if (args[i].equals("-t") || args[i].equals("--taggeronly")) {
        options.setTaggerOnly(true);
        if (options.isListUnknown()) {
          throw new IllegalArgumentException("You cannot list unknown words when tagging only");
        }
        if (options.isApplySuggestions()) {
          throw new IllegalArgumentException("You cannot apply suggestions when tagging only");
        }
      } else if (args[i].equals("-r") || args[i].equals("--recursive")) {
        options.setRecursive(true);
      } else if (args[i].equals("-b2") || args[i].equals("--bitext")) {
        options.setBitext(true);
      } else if (args[i].equals("-eo") || args[i].equals("--enabledonly")) {
        if (options.getDisabledRules().size() > 0) {
          throw new IllegalArgumentException("You cannot specify both disabled rules and enabledonly");
        }
        options.setUseEnabledOnly();
      } else if (args[i].equals("-d") || args[i].equals("--disable")) {
        if (options.isUseEnabledOnly()) {
          throw new IllegalArgumentException("You cannot specify both disabled rules and enabledonly");
        }
        checkArguments("-d/--disable", i, args);
        String rules = args[++i];
        options.setDisabledRules(Arrays.asList(rules.split(",")));
      } else if (args[i].equals("-e") || args[i].equals("--enable")) {
        checkArguments("-e/--enable", i, args);
        String rules = args[++i];
        options.setEnabledRules(Arrays.asList(rules.split(",")));
      } else if (args[i].equals("--enablecategories")) {
        checkArguments("--enablecategories", i, args);
        String categories = args[++i];
        options.setEnabledCategories(Arrays.asList(categories.split(",")));
      } else if (args[i].equals("--disablecategories")) {

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Remove -eo/--enabledonly if you need to disable specific rules.
  2. Remove the -d/--disable list if you truly want enabled-only mode.
  3. Switch to -e/--enable with an explicit rule list instead of mixing selection modes.

Example fix

// before
languagetool -d UPPERCASE_SENTENCE_START -eo -l en file.txt
// after
languagetool -eo -l en file.txt
Defensive patterns

Strategy: validation

Validate before calling

List<String> a = Arrays.asList(args);
if ((a.contains("-eo") || a.contains("--enabledonly")) &&
    (a.contains("-d") || a.contains("--disable"))) {
  throw new IllegalArgumentException("-eo and -d cannot be combined");
}

Try / catch

try {
  new CommandLineParser().parseOptions(args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("disabled rules and enabledonly")) {
    System.err.println("Use either -eo/--enabledonly or -d/--disable, never both.");
  }
}

Prevention

When it happens

Trigger: `languagetool -d GRAMMAR -eo -l en file.txt` — --disable parsed before --enabledonly with a non-empty disabled list.

Common situations: Users combining rule-selection flags without realizing the two are opposite selection modes; shell aliases appending -eo.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


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