Repository navigation
[Backport 4.0.x] Evaluate expressions without a mojo execution (fix #8052) - #13504
Conversation
…pache#8052) PluginParameterExpressionEvaluator(MavenSession) passes no MojoExecution, but evaluate() dereferenced it for every expression, so any ${...} failed with a NullPointerException. Only look at the mojo execution for the mojo and plugin expressions, which have no value without one, and evaluate everything else as before. Backport of the change to master, see apache#13497. Fixes apache#8052
gnodet-bot
left a comment
There was a problem hiding this comment.
LGTM. Clean, minimal backport — all NPE paths from mojoExecution/mojoDescriptor are properly guarded (the upfront ternary assignment, the startsWith("mojo") guard, the expression.equals("plugin") null-conditional, and the startsWith("plugin") guard). Tests are well-targeted: testEvaluationWithoutMojoExecution verifies that session/property expressions still work without a mojo execution, and testMojoAndPluginExpressionsWithoutMojoExecution confirms they return null rather than NPE.
Pre-fix validation ✅ — static trace confirms evaluate() would NPE at the first call before the fix (line 166 was unconditional mojoExecution.getMojoDescriptor() with mojoExecution = null). Author also confirmed test failures before the fix, three runs.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Backport of #13497 to
maven-4.0.x. Fixes #8052What and why
PluginParameterExpressionEvaluator(MavenSession)creates the evaluator without aMojoExecution, butevaluate()calledmojoExecution.getMojoDescriptor()for every expression. Any${...}therefore failed with aNullPointerException, as reported in the issue by a tool that uses the evaluator outside a mojo execution.How
The mojo descriptor is only read when there is a mojo execution. The
mojo.*andplugin.*expressions need one and have no value without it, so they evaluate to nothing, like any unknown expression, and fall back to the properties lookup. All other expressions are evaluated as before. The change is the same as on master.Tests
PluginParameterExpressionEvaluatorTesthas two new tests that use the single argument constructor. Both fail onmaven-4.0.xwith theNullPointerExceptionof the issue and pass with the change, three runs in a row. The test class passes (28 tests) and spotless is clean. I did not run the integration tests.To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following: