{"record":{"id":"80ac920beb246de4","repo":"elastic/elasticsearch","slug":"error-parsing-xml-file-in","errorCode":null,"errorMessage":"Error parsing xml file in {}","messagePattern":"Error parsing xml file in (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/shadow/XmlClassRelocationTransformer.java","lineNumber":68,"sourceCode":"        }\n        return false;\n    }\n\n    @Override\n    public void transform(TransformerContext context) {\n        try {\n            BufferedInputStream bis = new BufferedInputStream(context.getInputStream());\n            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();\n            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();\n            doc = dBuilder.parse(bis);\n            doc.getDocumentElement().normalize();\n            Node root = doc.getDocumentElement();\n            walkThroughNodes(root, context);\n            if (hasTransformedResource == false) {\n                this.doc = null;\n            }\n        } catch (Exception e) {\n            throw new RuntimeException(\"Error parsing xml file in \" + context.getInputStream(), e);\n        }\n    }\n\n    private static String getRelocatedClass(String className, TransformerContext context) {\n        Set<Relocator> relocators = context.getRelocators();\n        if (className != null && className.length() > 0 && relocators != null) {\n            for (Relocator relocator : relocators) {\n                if (relocator.canRelocateClass(className)) {\n                    RelocateClassContext relocateClassContext = new RelocateClassContext(className);\n                    return relocator.relocateClass(relocateClassContext);\n                }\n            }\n        }\n\n        return className;\n    }\n\n    private void walkThroughNodes(Node node, TransformerContext context) {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/shadow/XmlClassRelocationTransformer.java#L50-L86","documentation":"Thrown by the XML class-relocation transformer used during Gradle shadow/jar shading. It walks XML resource files (typically plugin descriptors like META-INF/xml-style descriptors) to rewrite class references to their relocated packages. The broad catch wraps any SAX/IO/parser failure with the offending input stream's toString().","triggerScenarios":"processResource() is invoked on a TransformerContext whose getInputStream() returns malformed, truncated, or non-XML content; dBuilder.parse(bis) throws SAXParseException, or the stream is already consumed/closed.","commonSituations":"A shaded dependency ships a corrupt XML descriptor; a resource was patched by another transformer leaving invalid XML; classpath contains a renamed XML file that no longer parses; encoding/BOM issues in a hand-edited descriptor.","solutions":["Inspect the full cause chain (the wrapped Exception e) to find the SAXParseException line/column.","Identify which jar/resource owns the stream shown in the message and open the original XML to validate it.","If the XML is intentionally non-relocatable, exclude that resource from the transformer's input set.","Reproduce with a standalone DocumentBuilder.parse() on the extracted file to confirm well-formedness."],"exampleFix":"// before\n} catch (Exception e) {\n    throw new RuntimeException(\"Error parsing xml file in \" + context.getInputStream(), e);\n}\n\n// after - keep the resource identity without re-reading a possibly-consumed stream\n} catch (Exception e) {\n    throw new RuntimeException(\"Error parsing xml file in \" + context.getName(), e);\n}","handlingStrategy":"try-catch","validationCode":"// Validate the XML is well-formed before passing it to the transformer\nDocumentBuilderFactory f = DocumentBuilderFactory.newInstance();\nf.setFeature(\"http://apache.org/xml/features/disallow-doctype-decl\", true);\ntry (InputStream in = context.getInputStream()) {\n    f.newDocumentBuilder().parse(in);\n} catch (SAXException | IOException ok) {\n    // skip this resource rather than feed invalid XML to the transformer\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    transformer.processResource(context);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Error parsing xml file in\")) {\n        // log the offending resource and continue shading other resources\n        logger.warn(\"Skipping unparseable XML resource\", e);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Pre-validate XML resources with a standalone parser in a build sanity step.","Exclude known-broken or non-relocatable XML resources from the transformer configuration.","Avoid hand-editing shaded descriptors; regenerate them from source."],"tags":["gradle","shadow-plugin","xml-parsing","build-tooling"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}