{"record":{"id":"1a2a14c49081dad0","repo":"languagetool-org/languagetool","slug":"advancedsynthesizerfilter-index-out-of-bounds-in-1a2a14","errorCode":null,"errorMessage":"AdvancedSynthesizerFilter: Index out of bounds in ${match.getRule().getFullId()}, value: ${lemmaFromStr}","messagePattern":"AdvancedSynthesizerFilter: Index out of bounds in (.+?), value: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/rules/AbstractAdvancedSynthesizerFilter.java","lineNumber":90,"sourceCode":"    }\n    if (postagFrom < 1 || postagFrom > patternTokens.length) {\n      throw new IllegalArgumentException(\"AdvancedSynthesizerFilter: Index out of bounds in \"\n          + match.getRule().getFullId() + \", value: \" + postagFromStr);\n    }\n    int lemmaFrom = 0;\n    if (lemmaFromStr.startsWith(\"marker\")) {\n      while (lemmaFrom < patternTokens.length && patternTokens[lemmaFrom].getStartPos() < match.getFromPos()) {\n        lemmaFrom++;\n      }\n      lemmaFrom++;\n      if (lemmaFromStr.length()>6) {\n        lemmaFrom += Integer.parseInt(lemmaFromStr.replace(\"marker\", \"\"));\n      }\n    } else {\n      lemmaFrom = Integer.parseInt(lemmaFromStr);\n    }\n    if (lemmaFrom < 1 || lemmaFrom > patternTokens.length) {\n      throw new IllegalArgumentException(\"AdvancedSynthesizerFilter: Index out of bounds in \"\n          + match.getRule().getFullId() + \", value: \" + lemmaFromStr);\n    }\n\n    String postagReplace = getOptional(\"postagReplace\", arguments);\n\n    String desiredLemma = getAnalyzedToken(patternTokens[lemmaFrom - 1], lemmaSelect).getLemma();\n    String originalPostag = getAnalyzedToken(patternTokens[lemmaFrom - 1], lemmaSelect).getPOSTag();\n    String desiredPostag = getAnalyzedToken(patternTokens[postagFrom - 1], postagSelect).getPOSTag();\n    if (!newLemma.isEmpty()) {\n      if (newLemma.startsWith(\"_\")) {\n        desiredLemma = getNewLemma(desiredLemma, newLemma);\n      } else {\n        desiredLemma = newLemma;\n      }\n    }\n    if (desiredLemma == null) {\n      return null;\n    }","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/rules/AbstractAdvancedSynthesizerFilter.java#L72-L108","documentation":"Same filter, same validation, but for the 'lemmaFrom' argument: acceptRuleMatch() requires lemma_from (absolute or marker-based) to fall within 1..patternTokens.length, because the token at that index supplies the lemma for synthesis. Out of range means the rule references a nonexistent token.","triggerScenarios":"A rule's lemma_from value (e.g. lemma_from=\"3\" or marker arithmetic) resolves to <1 or beyond the number of matched pattern tokens; patternTokens[lemmaFrom-1] would otherwise be accessed.","commonSituations":"Rule pattern edited/shortened without updating lemma_from; copy-paste of filter args between rules with different token counts; off-by-one (1-based indices).","solutions":["Correct lemma_from in the rule XML to a valid 1-based token index in the pattern.","After changing a pattern, revalidate all filter argument indices.","Verify marker arithmetic stays within the matched token count.","Run the rule's test sentences to exercise acceptRuleMatch and confirm the fix."],"exampleFix":"// before (3-token pattern, lemma_from:7)\n<filter class=\"...AdvancedSynthesizerFilter\" args=\"lemma_from:7 postag_from:2\"/>\n// after\n<filter class=\"...AdvancedSynthesizerFilter\" args=\"lemma_from:2 postag_from:2\"/>","handlingStrategy":"validation","validationCode":"int lemmaFrom = Integer.parseInt(args.get(\"lemma_from\").replace(\"marker\", \"\"));\nif (lemmaFrom < 1 || lemmaFrom > patternTokens.length)\n  throw new RuleFormatException(\"lemma_from out of range\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate lemma_from against the actual pattern token count","Avoid copy-pasting filter args between rules with different patterns","Add rule test cases that exercise the filter"],"tags":["grammar-rules","synthesizer","rule-configuration"],"backgroundTag":"index-out-of-range","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}