{"record":{"id":"3ba67793b60b8ffa","repo":"languagetool-org/languagetool","slug":"no-alternative-found-for","errorCode":null,"errorMessage":"No alternative found for: ","messagePattern":"No alternative found for: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/rules/ngrams/ConfusionProbabilityRule.java","lineNumber":309,"sourceCode":"    return grams;\n  }\n\n  @Nullable\n  private ConfusionString getBetterAlternativeOrNull(GoogleToken token, List<GoogleToken> tokens, List<ConfusionString> confusionSet, long factor) {\n    if (confusionSet.size() != 2) {\n      throw new RuntimeException(\"Confusion set must be of size 2: \" + confusionSet);\n    }\n    ConfusionString other = getAlternativeTerm(confusionSet, token);\n    return getBetterAlternativeOrNull(token, tokens, other, factor);\n  }\n\n  private ConfusionString getAlternativeTerm(List<ConfusionString> confusionSet, GoogleToken token) {\n    for (ConfusionString s : confusionSet) {\n      if (!s.getString().equals(token.token)) {\n        return s;\n      }\n    }\n    throw new RuntimeException(\"No alternative found for: \" + token);\n  }\n\n  private ConfusionString getConfusionString(List<ConfusionString> confusionSet, GoogleToken token) {\n    for (ConfusionString s : confusionSet) {\n      if (s.getString().equalsIgnoreCase(token.token)) {\n        return s;\n      }\n    }\n    throw new RuntimeException(\"Not found in set '\" + confusionSet + \"': \" + token);\n  }\n\n  private ConfusionString getBetterAlternativeOrNull(GoogleToken token, List<GoogleToken> tokens, ConfusionString otherWord, long factor) {\n    String word = token.token;\n    double p1;\n    double p2;\n    if (grams == 3) {\n      p1 = LanguageModelUtils.get3gramProbabilityFor(language, lm, token, tokens, word);\n      p2 = LanguageModelUtils.get3gramProbabilityFor(language, lm, token, tokens, otherWord.getString());","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/rules/ngrams/ConfusionProbabilityRule.java#L291-L327","documentation":"getAlternativeTerm scans the confusion set for the entry whose text differs from the current token to return as the alternative suggestion. This RuntimeException is thrown when no such entry exists, meaning every entry equals the token — an inconsistency given the size-2 precondition.","triggerScenarios":"A confusion set whose entries all equal the matched token (e.g. duplicated entries), so the loop finds no differing string and falls through to the throw.","commonSituations":"Confusion data containing the same word twice instead of two distinct words; token normalization differences that make both entries compare equal to the token.","solutions":["Check the token and confusion set contents reported in the message.","Fix the confusion data so the set holds two distinct words.","Verify token normalization/case handling doesn't collapse both entries to the same string."],"exampleFix":"// before (confusion data)\ntheir\ntheir\n// after (confusion data)\ntheir\nthere","handlingStrategy":"validation","validationCode":"// ensure the confusion set has two distinct entries before lookup\nif (set.stream().map(ConfusionString::getString).distinct().count() != 2)\n    throw new IllegalStateException(\"Confusion set entries must be distinct: \" + set);","typeGuard":null,"tryCatchPattern":"try { rule.match(...); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"No alternative found\")) log.error(\"Duplicated confusion data: \" + e.getMessage()); throw e; }","preventionTips":["Avoid duplicate lines in confusion data files","Sanity-check data with a distinct-entry assertion","Keep token normalization consistent with data entries"],"tags":["java","ngrams","invariant-violation","languagetool"],"backgroundTag":"internal-invariant-violation","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"}