{"record":{"id":"1b36cedbfddb062a","repo":"languagetool-org/languagetool","slug":"no-start-error-marker-errormarker-getstartmark","errorCode":null,"errorMessage":"No start error marker ( + errorMarker.getStartMarker() + ) found in text with correction","messagePattern":"No start error marker \\( \\+ errorMarker\\.getStartMarker\\(\\) \\+ \\) found in text with correction","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-wikipedia/src/main/java/org/languagetool/dev/wikipedia/RuleMatchApplication.java","lineNumber":44,"sourceCode":"public class RuleMatchApplication {\n\n  private final RuleMatch ruleMatch;\n  private final String text;\n  private final String textWithCorrection;\n  private final ErrorMarker errorMarker;\n  private final boolean hasRealReplacement;\n\n  static RuleMatchApplication forMatchWithReplacement(RuleMatch ruleMatch, String text, String textWithCorrection, ErrorMarker errorMarker) {\n    return new RuleMatchApplication(ruleMatch, text, textWithCorrection, errorMarker, true);\n  }\n\n  static RuleMatchApplication forMatchWithoutReplacement(RuleMatch ruleMatch, String text, String textWithCorrection, ErrorMarker errorMarker) {\n    return new RuleMatchApplication(ruleMatch, text, textWithCorrection, errorMarker, false);\n  }\n\n  private RuleMatchApplication(RuleMatch ruleMatch, String text, String textWithCorrection, ErrorMarker errorMarker, boolean hasRealReplacement) {\n    if (!textWithCorrection.contains(errorMarker.getStartMarker())) {\n      throw new IllegalArgumentException(\"No start error marker (\" + errorMarker.getStartMarker() + \") found in text with correction\");\n    }\n    if (!textWithCorrection.contains(errorMarker.getEndMarker())) {\n      throw new IllegalArgumentException(\"No end error marker (\" + errorMarker.getEndMarker() + \") found in text with correction\");\n    }\n    this.ruleMatch = ruleMatch;\n    this.text = text;\n    this.textWithCorrection = textWithCorrection;\n    this.errorMarker = errorMarker;\n    this.hasRealReplacement = hasRealReplacement;\n  }\n\n  public String getOriginalErrorContext(int contextSize) {\n    return getContext(text, contextSize);\n  }\n\n  public String getCorrectedErrorContext(int contextSize) {\n    return getContext(textWithCorrection, contextSize);\n  }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-wikipedia/src/main/java/org/languagetool/dev/wikipedia/RuleMatchApplication.java#L26-L62","documentation":"RuleMatchApplication's private constructor validates that the corrected text still contains the ErrorMarker's start marker. If the marker string is not present, it throws IllegalArgumentException because the marker positions needed to compute offsets cannot be determined.","triggerScenarios":"Creating a RuleMatchApplication (via forMatchWithReplacement/forMatchWithoutReplacement) where textWithCorrection was built without embedding the errorMarker start marker — markers stripped too early or marker mismatch.","commonSituations":"Test fixtures where the correction text was hand-edited and markers removed; error marker constants changed between the producer and consumer; double application of a correction removing markers.","solutions":["Ensure the correction text retains the errorMarker start marker (e.g. <err> tags) until RuleMatchApplication is created","Verify the same ErrorMarker instance/values used to produce textWithCorrection","Check that prior processing did not strip markup before this call","For tests, regenerate textWithCorrection with markers rather than editing it manually"],"exampleFix":"// before\nString corrected = plainResult.replace(\"mistke\", \"mistake\");\n// after\nString corrected = plainResult.replace(\"<err>mistke</err>\", \"<err>mistake</err>\"); // keep markers\nRuleMatchApplication.forMatchWithReplacement(match, text, corrected, errorMarker, true);","handlingStrategy":"validation","validationCode":"if (!textWithCorrection.contains(errorMarker.getStartMarker())) {\n  throw new IllegalStateException(\"correction text lost start marker\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  app = RuleMatchApplication.forMatchWithoutReplacement(match, text, corrected, marker);\n} catch (IllegalArgumentException e) {\n  LOG.error(\"markers missing in corrected text\", e);\n}","preventionTips":["Keep error markers intact through all text transformations","Generate corrected text programmatically, never hand-edit","Use one ErrorMarker constant set everywhere"],"tags":["marker-validation","wikipedia","illegal-argument"],"backgroundTag":"invalid-argument-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"}