{"record":{"id":"4608279106ef1de2","repo":"languagetool-org/languagetool","slug":"could-not-load-false-friend-rules-from","errorCode":null,"errorMessage":"Could not load false friend rules from ","messagePattern":"Could not load false friend rules from ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/rules/patterns/FalseFriendRuleLoader.java","lineNumber":69,"sourceCode":"    this.falseFriendSugg =  messages.getString(\"false_friend_suggestion\");\n    this.inTestMode = inTestMode;\n  }\n\n  public FalseFriendRuleLoader(String falseFriendHint, String falseFriendSugg) {\n    this.falseFriendHint = Objects.requireNonNull(falseFriendHint);\n    this.falseFriendSugg = Objects.requireNonNull(falseFriendSugg);\n    this.inTestMode = false;\n  }\n\n  /**\n   * @param file XML file with false friend rules\n   * @since 2.3\n   */\n  public final List<AbstractPatternRule> getRules(File file, Language language, Language motherTongue) throws IOException {\n    try (InputStream inputStream = new FileInputStream(file)) {\n      return getRules(inputStream, language, motherTongue);\n    } catch (ParserConfigurationException | SAXException e) {\n      throw new IOException(\"Could not load false friend rules from \" + file, e);\n    }\n  }\n\n  public final List<AbstractPatternRule> getRules(InputStream stream,\n      Language textLanguage, Language motherTongue)\n      throws ParserConfigurationException, SAXException, IOException {\n    FalseFriendRuleHandler handler = new FalseFriendRuleHandler(\n        textLanguage, motherTongue, falseFriendHint, inTestMode);\n    SAXParserFactory factory = SAXParserFactory.newInstance();\n    SAXParser saxParser = factory.newSAXParser();\n    saxParser.getXMLReader().setFeature(\n            \"http://apache.org/xml/features/nonvalidating/load-external-dtd\",\n            false);\n    saxParser.parse(stream, handler);\n    List<AbstractPatternRule> rules = handler.getRules();\n    List<AbstractPatternRule> filteredRules = new ArrayList<>();\n    // Add suggestions to each rule:\n    MessageFormat msgFormat = new MessageFormat(falseFriendSugg);","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/rules/patterns/FalseFriendRuleLoader.java#L51-L87","documentation":"FalseFriendRuleLoader.getRules reads a false-friend XML file and parses it. If the XML parser is misconfigured (ParserConfigurationException) or the document is malformed (SAXException), the loader wraps the cause in an IOException with this message plus the file path, so callers only need to handle IOException.","triggerScenarios":"Calling getRules(File, Language, Language) (directly or via loadFalseFriendRules/tests) on an XML file that is not well-formed: unclosed tags, invalid entities, encoding problems, or an unreachable/invalid DTD.","commonSituations":"Editing false-friends.xml and breaking its structure, wrong file encoding (not UTF-8), missing external DTD in offline environments, or pointing the loader at the wrong XML file type.","solutions":["Validate the false-friend XML file with an XML parser/linter to find the malformed element reported in the chained cause","Fix the XML syntax error at the location given by the wrapped SAXException","Ensure the file encoding matches the XML declaration (usually UTF-8)","Check DTD/stylesheet references resolve (network access or local copies for offline builds)"],"exampleFix":"// before (malformed)\n<rule id=\"X\">\n  <translation lang=\"de\">...</translation>\n</rul>\n// after\n<rule id=\"X\">\n  <translation lang=\"de\">...</translation>\n</rule>","handlingStrategy":"try-catch","validationCode":"try (InputStream in = new FileInputStream(file)) {\n  new XmlDocumentBuilderFactory().newDocumentBuilder().parse(in); // pre-validate well-formedness\n}","typeGuard":null,"tryCatchPattern":"try {\n  rules = loader.getRules(file, language, motherTongue);\n} catch (IOException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof SAXException) {\n    log.error(\"Malformed false-friend XML at {}: {}\", file, cause.getMessage());\n  }\n  throw e;\n}","preventionTips":["Validate rule XML files in CI before shipping","Keep files UTF-8 and consistent with the XML declaration","Ensure DTD/external references resolve in offline builds"],"tags":["xml-parsing","io-exception","false-friend","file-loading"],"backgroundTag":"file-read-failed","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"}