languagetool-org/languagetool · error · RuntimeException

Could not load SRX rules

Error message

Could not load SRX rules

What it means

The SRX segmentation rules file could not be read from the resource dir or parsed as SRX XML. createSrxDocument wraps I/O or parsing failures while building the SrxDocument used for sentence splitting; the input at fault is the SRX resource path passed in.

Source

Thrown at languagetool-core/src/main/java/org/languagetool/tokenizers/SrxTools.java:60

  private static final Map<String, Object> VALIDATION_PARAMETERS = Map.of(Srx2SaxParser.VALIDATE_PARAMETER, true);

  private static final Map<String, Object> TOKENIZE_PARAMETERS =
    Map.of(SrxTextIterator.DEFAULT_PATTERN_FLAGS_PARAMETER, Pattern.UNICODE_CHARACTER_CLASS);

  private SrxTools() {
  }

  static SrxDocument createSrxDocument(String path) {
    try {
      try (
        InputStream inputStream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(path);
        BufferedReader srxReader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))
      ) {
        SrxParser srxParser = new Srx2SaxParser(VALIDATION_PARAMETERS);
        return srxParser.parse(srxReader);
      }
    } catch (IOException e) {
      throw new RuntimeException("Could not load SRX rules", e);
    }
  }

  static List<String> tokenize(String text, SrxDocument srxDocument, String languageCode) {
    List<String> segments = new ArrayList<>();
    TextIterator textIterator = new SrxTextIterator(srxDocument, languageCode, text, TOKENIZE_PARAMETERS);
    while (textIterator.hasNext()) {
      segments.add(textIterator.next());
    }
    return segments;
  }

}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Verify the SRX file exists in the classpath/resource dir at the given path
  2. Check the SRX file is well-formed XML and valid against the SRX schema
  3. Inspect the chained cause for the underlying IOException or SAXException
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at languagetool-core/src/main/java/org/languagetool/tokenizers/SrxTools.java:60 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/9f12c1bb5f482122. Report an issue: GitHub.