{"record":{"id":"eeaabf5b5a220af1","repo":"languagetool-org/languagetool","slug":"enablemapping-not-activated","errorCode":null,"errorMessage":"enableMapping not activated","messagePattern":"enableMapping not activated","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"languagetool-wikipedia/src/main/java/org/languagetool/dev/wikipedia/TextConverter.java","lineNumber":104,"sourceCode":"  private boolean enableMapping = true;\n\n  // =========================================================================\n\n//  public TextConverter(SimpleWikiConfiguration config, int wrapCol) {\n//    this.config = config;\n//    this.wrapCol = wrapCol;\n//  }\n\n  public void enableMapping(boolean enableMapping) {\n    this.enableMapping = enableMapping;\n  }\n\n  /**\n   * Return a mapping from converted text positions to original text positions.\n   */\n  public Map<Integer, Location> getMapping() {\n    if (!enableMapping) {\n      throw new IllegalStateException(\"enableMapping not activated\");\n    }\n    return mapping;\n  }\n\n//  @Override\n//  protected boolean before(AstNode node) {\n//    // This method is called by go() before visitation starts\n//    sb = new StringBuilder();\n//    line = new StringBuilder();\n//    mapping = new HashMap<>();\n//    pastBod = false;\n//    needNewlines = 0;\n//    needSpace = false;\n//    noWrap = false;\n//    sections = new LinkedList<>();\n//    return super.before(node);\n//  }\n","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-wikipedia/src/main/java/org/languagetool/dev/wikipedia/TextConverter.java#L86-L122","documentation":"TextConverter optionally records a position mapping from converted text back to original text. getMapping() throws IllegalStateException when this feature was not enabled before conversion, since the mapping would be empty/meaningless.","triggerScenarios":"Calling getMapping() on a TextConverter created without enabling mapping (enableMapping flag false) — i.e., converting text but never activating position tracking.","commonSituations":"Forgetting to call the enable-mapping setter before convert(); reusing a converter instance configured for plain conversion when position mapping is later needed.","solutions":["Enable mapping on the converter before converting text","Create a new converter with mapping enabled if the text was already converted","Check the converter configuration before calling getMapping()"],"exampleFix":"// before\nTextConverter conv = new TextConverter();\nconv.convert(text);\nconv.getMapping(); // IllegalStateException\n// after\nTextConverter conv = new TextConverter();\nconv.setEnableMapping(true);\nconv.convert(text);\nconv.getMapping();","handlingStrategy":"try-catch","validationCode":"if (!converter.isEnableMapping()) { converter.setEnableMapping(true); }","typeGuard":null,"tryCatchPattern":"try {\n  mapping = converter.getMapping();\n} catch (IllegalStateException e) {\n  converter.setEnableMapping(true);\n  converted = converter.convert(originalText);\n  mapping = converter.getMapping();\n}","preventionTips":["Enable mapping at converter construction time if positions are needed later","Never reuse a non-mapping converter for position queries","Wrap converter config in a factory method"],"tags":["state","converter","wikipedia"],"backgroundTag":"invalid-state-transition","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"}