elharo opened a new pull request, #12932:
URL: https://github.com/apache/maven/pull/12932
Fixes #10598 (MNG-8174)
### Problem
When a POM property references itself (e.g. `<prop>${prop}</prop>`) and that
property is also used inside a plugin configuration attribute such as
`<filter token="key" value="${prop}"/>`, invoking the model interpolation
throws
```
java.lang.NullPointerException: Attribute value can not be null
at org.codehaus.plexus.util.xml.Xpp3Dom.setAttribute(Xpp3Dom.java:179)
at
...StringVisitorModelInterpolator$ModelVisitor.visit(StringVisitorModelInterpolator.java:727)
```
A recursive expression cycle is detected by the interpolator, which then
returns `null` for the unresolved expression. `visit(Xpp3Dom)` in
`StringVisitorModelInterpolator` unconditionally called
`dom.setAttribute(attr, val)` (and `dom.setValue(val)`) even when the
interpolated value was `null`, causing the NPE. The `visit(Properties)`
method already guarded against `null` in the identical situation.
### Fix
When interpolation of an Xpp3Dom content value or attribute returns `null`
(which happens on a recursive expression cycle), leave the original value
untouched instead of writing `null` into the DOM. This mirrors the existing
guard in `visit(Properties)`.
### Test
Added `testRecursiveExpressionCycleInPluginConfiguration` to
`AbstractModelInterpolatorTest`, which builds a model with a
self-referencing property and a plugin configuration attribute referencing
it. Before the fix the test fails with the NPE above; after the fix the
interpolation completes, reports the recursive-expression-cycle error and
the attribute keeps its original value.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]