{"record":{"id":"6a793fd2e8088690","repo":"mybatis/mybatis-3","slug":"error-evaluating-xpath-cause","errorCode":null,"errorMessage":"Error evaluating XPath.  Cause: {}","messagePattern":"Error evaluating XPath\\.  Cause: (.+?)","errorType":"exception","errorClass":"BuilderException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/parsing/XPathParser.java","lineNumber":225,"sourceCode":"  }\n\n  public XNode evalNode(String expression) {\n    return evalNode(document, expression);\n  }\n\n  public XNode evalNode(Object root, String expression) {\n    Node node = (Node) evaluate(expression, root, XPathConstants.NODE);\n    if (node == null) {\n      return null;\n    }\n    return new XNode(this, node, variables);\n  }\n\n  private Object evaluate(String expression, Object root, QName returnType) {\n    try {\n      return xpath.evaluate(expression, root, returnType);\n    } catch (Exception e) {\n      throw new BuilderException(\"Error evaluating XPath.  Cause: \" + e, e);\n    }\n  }\n\n  private Document createDocument(InputSource inputSource) {\n    // important: this must only be called AFTER common constructor\n    try {\n      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n      factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);\n      factory.setValidating(validation);\n\n      factory.setNamespaceAware(false);\n      factory.setIgnoringComments(true);\n      factory.setIgnoringElementContentWhitespace(false);\n      factory.setCoalescing(false);\n      factory.setExpandEntityReferences(false);\n\n      DocumentBuilder builder = factory.newDocumentBuilder();\n      builder.setEntityResolver(entityResolver);","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/parsing/XPathParser.java#L207-L243","documentation":"XPathParser.evaluate() wraps any exception thrown by javax.xml.xpath.XPath.evaluate() into a BuilderException. This is MyBatis-internal XPath evaluation over the parsed mapper/config DOM, so a failure means the XPath expression could not be applied to the document.","triggerScenarios":"Malformed or exotic XML that leads internal evalNode/eval calls astray, or a caller using XPathParser's public eval* methods with an invalid XPath expression (syntax error or unsupported construct).","commonSituations":"Custom tooling built on XPathParser passing hand-crafted XPath strings; corrupted or non-standard mapper XML (wrong DOCTYPE, unexpected element names) that breaks internal lookups.","solutions":["Validate the mapper/configuration XML against the MyBatis DTD/XSD and fix structural issues.","If using XPathParser directly, test the XPath expression in isolation (e.g. with a plain XPath engine) before passing it.","Check the cause chain in the BuilderException — the wrapped exception states the exact XPath failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  XNode node = parser.evalNode(\"/configuration/environments\");\n} catch (BuilderException e) {\n  // log the cause chain; the wrapped XPathException pinpoints the bad expression\n}","preventionTips":["When using XPathParser programmatically, unit-test every XPath literal against a sample document.","Keep mapper XML conforming to the official DTD so internal expression paths stay valid."],"tags":["mybatis","xml","xpath","parsing"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}