{"record":{"id":"ac51669aa4264952","repo":"spring-projects/spring-boot","slug":"invalid-layers-xml-configuration","errorCode":null,"errorMessage":"Invalid layers.xml configuration","messagePattern":"Invalid layers\\.xml configuration","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CustomLayersProvider.java","lineNumber":72,"sourceCode":"class CustomLayersProvider {\n\n\tCustomLayers getLayers(Document document) {\n\t\tvalidate(document);\n\t\tElement root = document.getDocumentElement();\n\t\tList<ContentSelector<String>> applicationSelectors = getApplicationSelectors(root);\n\t\tList<ContentSelector<Library>> librarySelectors = getLibrarySelectors(root);\n\t\tList<Layer> layers = getLayers(root);\n\t\treturn new CustomLayers(layers, applicationSelectors, librarySelectors);\n\t}\n\n\tprivate void validate(Document document) {\n\t\tSchema schema = loadSchema();\n\t\ttry {\n\t\t\tValidator validator = schema.newValidator();\n\t\t\tvalidator.validate(new DOMSource(document));\n\t\t}\n\t\tcatch (SAXException | IOException ex) {\n\t\t\tthrow new IllegalStateException(\"Invalid layers.xml configuration\", ex);\n\t\t}\n\t}\n\n\tprivate Schema loadSchema() {\n\t\ttry {\n\t\t\tSchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\n\t\t\treturn factory.newSchema(getClass().getResource(\"layers.xsd\"));\n\t\t}\n\t\tcatch (SAXException ex) {\n\t\t\tthrow new IllegalStateException(\"Unable to load layers XSD\");\n\t\t}\n\t}\n\n\tprivate List<ContentSelector<String>> getApplicationSelectors(Element root) {\n\t\treturn getSelectors(root, \"application\", (element) -> getSelector(element, ApplicationContentFilter::new));\n\t}\n\n\tprivate List<ContentSelector<Library>> getLibrarySelectors(Element root) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CustomLayersProvider.java#L54-L90","documentation":"IllegalStateException thrown by CustomLayersProvider.validate when XSD validation of the layers document fails with a SAXException (schema violation, malformed element) or IOException (unable to read a referenced resource). The bundled layers.xsd defines the legal grammar; this guard fires before any structural interpretation.","triggerScenarios":"A layers.xml that violates the XSD: unknown elements, missing required attributes, wrong nesting, content type mismatch, or any SAX-reported validity error. Also fires on IOException if the validator needs external resolution and I/O fails.","commonSituations":"Hand-edited layers.xml with element typos; using a feature from a newer Spring Boot against an older plugin (or vice versa) where the schema differs; copy-pasted example with a missing required attribute such as layer= on <into>.","solutions":["Open the chained SAXException — it gives line/column and the failed constraint.","Validate against the bundled layers.xsd shipped with your plugin version using an XML editor or `xmllint --schema`.","Correct element/attribute names and required values per the current schema.","Use Spring Boot's documented example as a baseline and incrementally add customizations."],"exampleFix":"// before: <into><include>**/*</include></into>   <!-- missing required 'layer' attribute -->\n// after:  <into layer=\"application\"><include>**/*</include></into>","handlingStrategy":"validation","validationCode":"// XSD-validate layers.xml in CI before the plugin runs:\nSchema s = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)\n    .newSchema(new File(\"layers.xsd\"));\nValidator v = s.newValidator();\nv.validate(new StreamSource(new File(\"src/main/resources/META-INF/spring/layers/custom.xml\")));","typeGuard":null,"tryCatchPattern":"try {\n    // invoke goal that triggers CustomLayersProvider.validate\n} catch (IllegalStateException ex) {\n    if (\"Invalid layers.xml configuration\".equals(ex.getMessage())) {\n        Throwable c = ex.getCause(); // SAXParseException with line/column\n    }\n    throw ex;\n}","preventionTips":["Commit layers.xsd alongside layers.xml and validate in CI.","Author layers.xml from the official example, then edit minimally.","Match plugin version to schema version."],"tags":["spring-boot","maven-plugin","layers","xsd","validation"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}