{"record":{"id":"412e1f19c703e748","repo":"spring-projects/spring-boot","slug":"failed-to-process-custom-layers-configuration-sou","errorCode":null,"errorMessage":"Failed to process custom layers configuration {source}","messagePattern":"Failed to process custom layers configuration (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractPackagerMojo.java","lineNumber":227,"sourceCode":"\t\treturn IMPLICIT_LAYERS;\n\t}\n\n\tprivate InputStream loadLayersConfigurationFromClasspath(String name, String location) {\n\t\tInputStream in = this.pluginDescriptor.getClassRealm().getResourceAsStream(location);\n\t\tif (in == null) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\"Failed to load layers configuration with name '%s': '%s' not found\".formatted(name, location));\n\t\t}\n\t\treturn in;\n\t}\n\n\tprivate CustomLayers getCustomLayers(String source, InputStreamSource inputStreamSource) {\n\t\ttry {\n\t\t\tDocument document = getDocumentIfAvailable(inputStreamSource);\n\t\t\treturn new CustomLayersProvider().getLayers(document);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new IllegalStateException(\"Failed to process custom layers configuration \" + source, ex);\n\t\t}\n\t}\n\n\tprivate Document getDocumentIfAvailable(InputStreamSource source) throws Exception {\n\t\ttry (InputStream in = source.getInputStream()) {\n\t\t\tInputSource inputSource = new InputSource(in);\n\t\t\tDocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n\t\t\tfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);\n\t\t\tfactory.setFeature(\"http://apache.org/xml/features/disallow-doctype-decl\", true);\n\t\t\tfactory.setNamespaceAware(true);\n\t\t\tDocumentBuilder builder = factory.newDocumentBuilder();\n\t\t\treturn builder.parse(inputSource);\n\t\t}\n\t}\n\n\t/**\n\t * Return {@link Libraries} that the packager can use.\n\t * @param unpacks any libraries that require unpack","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractPackagerMojo.java#L209-L245","documentation":"Wrapped IllegalStateException thrown by AbstractPackagerMojo.getCustomLayers when any Exception occurs while turning the layers XML into a CustomLayers object. The pipeline is: open the InputStream, build a secure DocumentBuilderFactory, parse, then hand the Document to CustomLayersProvider.getLayers. Anything from XML parsing errors, XSD validation failures, malformed content, or programmatic CustomLayers construction failures lands here.","triggerScenarios":"A layers.xml that is malformed XML, references unknown elements, fails XSD validation, or triggers an exception inside CustomLayersProvider.getLayers/CustomLayers construction. The catch is broad (catch Exception) and wraps the cause.","commonSituations":"Hand-authored layers.xml with typos or wrong element names; an older layers.xml format used against a newer plugin that tightened the schema; encoding issues in the XML; an accidental <application>/<dependencies> selector referencing an invalid filter shape.","solutions":["Read the wrapped cause (ex) in the stack trace — it carries the precise XML/SAX or runtime error to fix.","Validate your layers.xml against the bundled layers.xsd (see CustomLayersProvider.loadSchema) using any XSD validator.","Align the layers.xml format with the Spring Boot version of the plugin you are running.","Remove the <configurationName> temporarily to confirm the build succeeds with IMPLICIT_LAYERS, isolating the problem to your custom file."],"exampleFix":"// before: <layers><application><into><include>**/*</include></into></application></layers>  <!-- malformed -->\n// after:  <layers><application><into layer=\"dependencies\"><include>**/*</include></into></application></layers>","handlingStrategy":"validation","validationCode":"// Validate layers.xml against the bundled XSD before invoking the plugin goal:\nSchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\nSchema schema = sf.newSchema(getClass().getResource(\"/org/springframework/boot/maven/layers.xsd\"));\nValidator v = schema.newValidator();\nv.setErrorHandler(new CollectingErrorHandler()); // collect all errors\nv.validate(new StreamSource(layersXmlFile));\n// fail fast if any errors collected","typeGuard":null,"tryCatchPattern":"try {\n    // invoke goal that triggers getCustomLayers\n} catch (IllegalStateException ex) {\n    if (ex.getMessage().startsWith(\"Failed to process custom layers configuration\")) {\n        Throwable cause = ex.getCause(); // SAX/IO/runtime detail\n    }\n    throw ex;\n}","preventionTips":["Treat layers.xml as code: commit it, lint it with xmllint --schema in CI.","Lock the spring-boot-maven-plugin version to match the layers schema you authored against.","Add a unit test that parses your layers.xml with CustomLayersProvider."],"tags":["spring-boot","maven-plugin","layers","xml","validation"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}