Skip to content

[Backport 4.0.x] Evaluate expressions without a mojo execution (fix #8052) - #13504

Merged
gnodet merged 1 commit into
apache:maven-4.0.xfrom
arturobernalg:backport/maven-4.0.x-8052-evaluator-without-mojo-execution
Oct 14, 2026
Merged

gnodet merged 1 commit into
apache:maven-4.0.xfrom
arturobernalg:backport/maven-4.0.x-8052-evaluator-without-mojo-execution

Conversation

@arturobernalg

@arturobernalg arturobernalg commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Backport of #13497 to maven-4.0.x. Fixes #8052

What and why

PluginParameterExpressionEvaluator(MavenSession) creates the evaluator without a MojoExecution, but evaluate() called mojoExecution.getMojoDescriptor() for every expression. Any ${...} therefore failed with a NullPointerException, 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.* and plugin.* 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

PluginParameterExpressionEvaluatorTest has two new tests that use the single argument constructor. Both fail on maven-4.0.x with the NullPointerException of 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:

…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 gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gnodet gnodet added bug Something isn't working backport java Pull requests that update Java code labels Oct 14, 2026
@gnodet gnodet added this to the 4.0.0 milestone Oct 14, 2026
@gnodet
gnodet merged commit 33f279f into apache:maven-4.0.x Oct 14, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bug Something isn't working java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants