languagetool-org/languagetool · error · IOException
Cannot load or parse '" + filename + "'
Error message
Cannot load or parse '" + filename + "'
What it means
BitextPatternRuleLoader.getRules wraps any exception from SAX parsing or rule-building of a bitext rule file into an IOException with the message "Cannot load or parse '<filename>'" and the original exception as cause. It is a catch-all conversion: the real problem (malformed XML, unsupported element, IO error) is in the cause chain. The loader is called by getBitextRules when loading bilingual pattern rules.
Source
Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/bitext/BitextPatternRuleLoader.java:48
/**
* Loads {@link PatternRule}s from an XML file.
*
* @author Marcin Miłkowski
*/
public class BitextPatternRuleLoader extends DefaultHandler {
public final List<BitextPatternRule> getRules(InputStream is, String filename) throws IOException {
List<BitextPatternRule> rules;
try {
BitextPatternRuleHandler handler = new BitextPatternRuleHandler();
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
saxParser.getXMLReader().setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
saxParser.parse(is, handler);
rules = handler.getBitextRules();
return rules;
} catch (Exception e) {
throw new IOException("Cannot load or parse '" + filename + "'", e);
}
}
}
View on GitHub (pinned to 2e990059ce)
Solutions
- Read the 'Caused by' chain of the IOException to find the real parse error and its line number
- Validate the bitext XML file with an XML parser/linter before loading
- Check that the filename/path is correct and the InputStream is readable and not already consumed
- Remove bitext-unsupported elements (e.g. triggers_error) revealed by the cause
Example fix
// before
try (InputStream is = new FileInputStream("rules.xml")) { ... }
// after: verify cause and file existence first
File f = new File("rules.xml");
if (!f.isFile()) throw new FileNotFoundException("rules.xml");
try (InputStream is = new FileInputStream(f)) { loader.getRules(is, "rules.xml"); } Defensive patterns
Strategy: try-catch
Validate before calling
File f = new File(filename);
if (!f.isFile() || !f.canRead()) throw new FileNotFoundException(filename);
try (InputStream probe = new FileInputStream(f)) {
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(probe); // fail fast on malformed XML
} Try / catch
try {
rules = BitextPatternRuleLoader.getBitextRules(stream, filename, srcLang, trgLang);
} catch (IOException e) {
Throwable cause = e.getCause();
log.error("Failed to load bitext rules from " + filename + ": " + cause, e);
if (cause instanceof SAXException) { /* point author at line/column */ }
} Prevention
- Always inspect the IOException's cause chain for the real parse error
- Validate bitext XML files with an XML parser before loading
- Confirm the file path and that the InputStream is fresh/unconsumed
- Avoid bitext-unsupported features (e.g. triggers_error) in bilingual rules
When it happens
Trigger: Any failure during factory.newSAXParser(), saxParser.parse(is, handler), or handler.getBitextRules() — e.g. malformed XML, bitext-unsupported elements like triggers_error, or a broken input stream — inside the try block.
Common situations: Malformed or hand-edited bitext rule XML; missing file/stream miswired so parse fails; using bitext-unsupported features; XML parser feature misconfiguration.
Related errors
- 'triggers_error' is not supported for bitext XML
- Could not tag and disambiguate '<token>'
- JSON output format is not implemented for Bitext
- You have to set the source language (as mother tongue) in bi
- Format error in file ${path}, line: ${line}
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/24d6cf99c08f9ae9.
Report an issue: GitHub.