{"record":{"id":"70bd4a6dc4c31e94","repo":"apache/maven","slug":"cannot-read-project-model-from-interpolating-filte","errorCode":null,"errorMessage":"Cannot read project model from interpolating filter of serialized version.","messagePattern":"Cannot read project model from interpolating filter of serialized version\\.","errorType":"exception","errorClass":"ModelInterpolationException","httpStatus":null,"severity":"error","filePath":"compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java","lineNumber":151,"sourceCode":"        StringWriter sWriter = new StringWriter(1024);\n\n        MavenStaxWriter writer = new MavenStaxWriter();\n        try {\n            writer.write(sWriter, model.getDelegate());\n        } catch (IOException | XMLStreamException e) {\n            throw new ModelInterpolationException(\"Cannot serialize project model for interpolation.\", e);\n        }\n\n        String serializedModel = sWriter.toString();\n        serializedModel = interpolate(serializedModel, model, projectDir, config, debugEnabled);\n\n        StringReader sReader = new StringReader(serializedModel);\n\n        MavenStaxReader modelReader = new MavenStaxReader();\n        try {\n            model = new Model(modelReader.read(sReader));\n        } catch (XMLStreamException e) {\n            throw new ModelInterpolationException(\n                    \"Cannot read project model from interpolating filter of serialized version.\", e);\n        }\n\n        return model;\n    }\n\n    /**\n     * Interpolates all expressions in the src parameter.\n     * <p>\n     * The algorithm used for each expression is:\n     * <ul>\n     *   <li>If it starts with either \"pom.\" or \"project.\", the expression is evaluated against the model.</li>\n     *   <li>If the value is null, get the value from the context.</li>\n     *   <li>If the value is null, but the context contains the expression, don't replace the expression string\n     *       with the value, and continue to find other expressions.</li>\n     *   <li>If the value is null, get it from the model properties.</li>\n     * </ul>\n     */","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java#L133-L169","documentation":"Thrown by AbstractStringBasedModelInterpolator after interpolation succeeds textually but the result no longer parses as XML. The serialized model was string-interpolated, then handed to MavenStaxReader; an XMLStreamException at this read-back step means interpolation injected content that broke XML well-formedness. This is the classic 'property value with special characters' failure of the string-based interpolation strategy.","triggerScenarios":"A ${property} used in an XML-sensitive position (element text or attribute) whose value contains raw '<', '>', '&' or quotes, e.g. <name>${project.description}</name> where the description contains an ampersand; or an interpolation that empties a required structure leaving dangling tags.","commonSituations":"Descriptions/names with '&' (e.g. 'R&D module') read from env vars or -D properties; properties holding XML fragments inserted into <url> or <name>; legacy Maven 2/3 string interpolation path chosen by old plugins (newer Maven uses field-wise interpolation that avoids this entirely).","solutions":["Escape or avoid & < > in property values used inside the POM ('R&amp;D' or plain 'and')","Upgrade to a Maven version using field-wise interpolation (Maven 3.4+/4 lines) or the StringSearchModelInterpolator instead of string-based interpolation","Move XML-unsafe text out of the POM (README, filtered resources) rather than interpolating it into the model","If you control the property source, sanitize values before they reach the build"],"exampleFix":"# before\nmvn install -Dproject.description=\"R&D platform\"\n# after\nmvn install -Dproject.description='R&amp;D platform'   # if consumed raw into XML\n# or better: keep such text out of the model entirely","handlingStrategy":"validation","validationCode":"// Escape XML metacharacters in any property that lands inside the POM\nstatic String xmlEscape(String v) {\n    return v.replace(\"&\",\"&amp;\").replace(\"<\",\"&lt;\").replace(\">\",\"&gt;\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    model = interpolator.interpolate(model, ...);\n} catch (ModelInterpolationException e) {\n    if (e.getMessage().contains(\"Cannot read project model\")) {\n        // an interpolated value broke XML: find the property with raw & < > and escape it\n    }\n}","preventionTips":["Keep '&', '<', '>' out of properties interpolated into the POM","Prefer newer Maven interpolation (field-wise) which is immune to this class of bug","Validate -D property values in wrapper scripts before invoking Maven"],"tags":["maven","interpolation","xml","escaping","properties"],"backgroundTag":"xml-parse-failed","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}