apache/maven · error · ModelInterpolationException
Cannot read project model from interpolating filter of seria
Error message
Cannot read project model from interpolating filter of serialized version.
What it means
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.
Source
Thrown at compat/maven-compat/src/main/java/org/apache/maven/project/interpolation/AbstractStringBasedModelInterpolator.java:151
StringWriter sWriter = new StringWriter(1024);
MavenStaxWriter writer = new MavenStaxWriter();
try {
writer.write(sWriter, model.getDelegate());
} catch (IOException | XMLStreamException e) {
throw new ModelInterpolationException("Cannot serialize project model for interpolation.", e);
}
String serializedModel = sWriter.toString();
serializedModel = interpolate(serializedModel, model, projectDir, config, debugEnabled);
StringReader sReader = new StringReader(serializedModel);
MavenStaxReader modelReader = new MavenStaxReader();
try {
model = new Model(modelReader.read(sReader));
} catch (XMLStreamException e) {
throw new ModelInterpolationException(
"Cannot read project model from interpolating filter of serialized version.", e);
}
return model;
}
/**
* Interpolates all expressions in the src parameter.
* <p>
* The algorithm used for each expression is:
* <ul>
* <li>If it starts with either "pom." or "project.", the expression is evaluated against the model.</li>
* <li>If the value is null, get the value from the context.</li>
* <li>If the value is null, but the context contains the expression, don't replace the expression string
* with the value, and continue to find other expressions.</li>
* <li>If the value is null, get it from the model properties.</li>
* </ul>
*/View on GitHub (pinned to e4093d4e12)
Solutions
- Escape or avoid & < > in property values used inside the POM ('R&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
Example fix
# before mvn install -Dproject.description="R&D platform" # after mvn install -Dproject.description='R&D platform' # if consumed raw into XML # or better: keep such text out of the model entirely
Defensive patterns
Strategy: validation
Validate before calling
// Escape XML metacharacters in any property that lands inside the POM
static String xmlEscape(String v) {
return v.replace("&","&").replace("<","<").replace(">",">");
} Try / catch
try {
model = interpolator.interpolate(model, ...);
} catch (ModelInterpolationException e) {
if (e.getMessage().contains("Cannot read project model")) {
// an interpolated value broke XML: find the property with raw & < > and escape it
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Cannot serialize project model for interpolation.
- Unable to parse unicode value: %s
- Unable to parse unicode value: {}
- Unable to convert configuration to xml node
- Cannot evaluate expression '%s' for configuration entry '%s'
AI-assisted analysis of apache/maven@e4093d4e12 (2026-08-21).
Data as JSON: /api/errors/70bd4a6dc4c31e94.
Report an issue: GitHub.