{"record":{"id":"0149636db49131a0","repo":"languagetool-org/languagetool","slug":"unknown-mode-mode","errorCode":null,"errorMessage":"Unknown mode: <mode>","messagePattern":"Unknown mode: <mode>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/JLanguageTool.java","lineNumber":2120,"sourceCode":"    public CheckResults call() throws Exception {\n      List<RuleMatch> ruleMatches = new ArrayList<>();\n      List<Range> ignoreRanges = new ArrayList<>();\n      List<ExtendedSentenceRange> extendedSentenceRanges = new ArrayList<>();\n      if (mode == Mode.ALL) {\n        ruleMatches.addAll(getTextLevelRuleMatches());\n        CheckResults otherRuleMatches = getOtherRuleMatches(toneTags);\n        ruleMatches.addAll(otherRuleMatches.getRuleMatches());\n        ignoreRanges.addAll(otherRuleMatches.getIgnoredRanges());\n        extendedSentenceRanges.addAll(otherRuleMatches.getExtendedSentenceRanges());\n      } else if (mode == Mode.ALL_BUT_TEXTLEVEL_ONLY) {\n        CheckResults otherRuleMatches = getOtherRuleMatches(toneTags);\n        ruleMatches.addAll(otherRuleMatches.getRuleMatches());\n        ignoreRanges.addAll(otherRuleMatches.getIgnoredRanges());\n        extendedSentenceRanges.addAll(otherRuleMatches.getExtendedSentenceRanges());\n      } else if (mode == Mode.TEXTLEVEL_ONLY) {\n        ruleMatches.addAll(getTextLevelRuleMatches());\n      } else {\n        throw new IllegalArgumentException(\"Unknown mode: \" + mode);\n      }\n      // can't call applyCustomRuleFilters here, done in performCheck ->\n      // should run just once w/ complete list of matches\n      return new CheckResults(ruleMatches, ignoreRanges, extendedSentenceRanges);\n    }\n\n    private List<RuleMatch> getTextLevelRuleMatches() throws IOException {\n      List<RuleMatch> ruleMatches = new ArrayList<>();\n      List<AnalyzedSentence> analyzedSentences = null;\n      for (Rule rule : rules.allRules()) {\n        if (rule instanceof TextLevelRule && paraMode != ParagraphHandling.ONLYNONPARA) {\n          if (checkCancelledCallback != null && checkCancelledCallback.checkCancelled()) {\n            break;\n          }\n          if (analyzedSentences == null) {\n            analyzedSentences = sentences.stream().map(s -> s.analyzed).collect(Collectors.toList());\n          }\n          RuleMatch[] matches = ((TextLevelRule) rule).match(analyzedSentences, annotatedText);","sourceCodeStart":2102,"sourceCodeEnd":2138,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/JLanguageTool.java#L2102-L2138","documentation":"JLanguageTool.check() dispatches on the configured Mode (e.g. ALL, TEXTLEVEL_ONLY); if the mode variable holds a value the switch/if-chain does not recognize, it throws IllegalArgumentException. This guards against enum values added later that this code path does not yet handle.","triggerScenarios":"Running check() with a Mode value that is neither ALL nor TEXTLEVEL_ONLY in the dispatch path, e.g. ModeLoadingLoopMode confusion or a null/custom mode value.","commonSituations":"Passing Mode.BOTH or a mode constant from a different LanguageTool version that the current check pipeline does not implement; programming error rather than user input.","solutions":["Use Mode.ALL or Mode.TEXTLEVEL_ONLY, the supported modes for this code path","Upgrade LanguageTool so the code recognizes your Mode value","Check for null mode before calling check()"],"exampleFix":"// before\nlt.setMode(mode); // mode is an unrecognized value\nlt.check(text); // IllegalArgumentException: Unknown mode\n// after\nlt.setMode(Mode.ALL);\nlt.check(text);","handlingStrategy":"validation","validationCode":"if (mode == null || (mode != Mode.ALL && mode != Mode.TEXTLEVEL_ONLY)) throw new IllegalArgumentException(\"Unsupported mode: \" + mode);","typeGuard":null,"tryCatchPattern":"try { results = lt.check(text); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Unknown mode\")) { lt.setMode(Mode.ALL); results = lt.check(text); } }","preventionTips":["Only use Mode constants documented for your LanguageTool version","Avoid passing user input as a Mode; map strings to known constants explicitly","After upgrading LanguageTool, verify custom mode handling still exists"],"tags":["java","illegal-argument","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}