elastic/elasticsearch · error · GradleException
Error parsing xml report ${xmlReportFileAbsolutePath}
Error message
Error parsing xml report ${xmlReportFileAbsolutePath} What it means
After generating the RAT XML report, unapprovedFiles parses it with a secured DocumentBuilderFactory to list resources whose license-approval is false. If the parse fails (SAXException, IOException, or ParserConfigurationException) this GradleException is thrown. Notably the original exception is not attached as a cause, which makes diagnosis harder.
Source
Thrown at build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/LicenseHeadersTask.java:337
writer.close();
return stats;
}
private static List<String> unapprovedFiles(File xmlReportFile) {
try {
NodeList resourcesNodes = createXmlDocumentBuilderFactory().newDocumentBuilder()
.parse(xmlReportFile)
.getElementsByTagName("resource");
return elementList(resourcesNodes).stream()
.filter(
resource -> elementList(resource.getChildNodes()).stream()
.anyMatch(n -> n.getTagName().equals("license-approval") && n.getAttribute("name").equals("false"))
)
.map(e -> e.getAttribute("name"))
.sorted()
.collect(Collectors.toList());
} catch (SAXException | IOException | ParserConfigurationException e) {
throw new GradleException("Error parsing xml report " + xmlReportFile.getAbsolutePath());
}
}
private static DocumentBuilderFactory createXmlDocumentBuilderFactory() throws ParserConfigurationException {
final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setXIncludeAware(false);
dbf.setIgnoringComments(true);
dbf.setExpandEntityReferences(false);
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
return dbf;
}
View on GitHub (pinned to db6a809a66)
Solutions
- Open the report file at the printed path and check it is well-formed XML.
- Delete the report and rerun with `--rerun-tasks` to regenerate it cleanly.
- If ParserConfigurationException, check the JDK vendor/version supports disallow-doctype-decl and FEATURE_SECURE_PROCESSING.
- Free disk space if the file is truncated.
Example fix
// before: truncated report from a previous failed run rm build/reports/licenseHeaders/rat.xml && ./gradlew licenseHeaders --rerun-tasks
Defensive patterns
Strategy: validation
Validate before calling
File xml = reportFile.getAsFile().get();
if (!xml.isFile() || xml.length() == 0) {
throw new GradleException("RAT XML report missing or empty: " + xml);
}
// Optionally validate well-formedness before parsing
DocumentBuilderFactory dbf = createXmlDocumentBuilderFactory();
dbf.newDocumentBuilder().parse(xml); Try / catch
try {
return unapprovedFiles(xmlReportFile);
} catch (GradleException e) {
// The wrapper drops the cause; re-open the file to diagnose
if (!xmlReportFile.isFile()) { throw new GradleException("Report vanished: " + xmlReportFile); }
throw e;
} Prevention
- Always regenerate the report in the same invocation that parses it (avoid leftover files).
- Run with --rerun-tasks after a disk-full or interrupted build.
- Confirm the runtime JDK supports the secured JAXP features the factory sets.
When it happens
Trigger: The XML report file is empty, truncated, or malformed when DocumentBuilder.parse runs; the JAXP configuration rejects the secured features (ParserConfigurationException); the report file was deleted between generation and parsing.
Common situations: A previous generateReport wrote a partial/corrupt file (disk full, interrupted); an XML parser feature unsupported by the runtime JDK; the reportFile was concurrently modified; antivirus quarantined the XML.
Related errors
- Cannot generate license header report for ${path}
- Cannot read ${f} to check for duplicate license headers
- Failed to write keywords report
- License category name must be exactly 5 characters, got ${ca
- Classes from a previous version have been modified, violatin
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/8b6e74d9175c4de9.
Report an issue: GitHub.