Sitelet https://github.com/apache/maven/pull/13020
Skip to content

[Backport 4.0.x] Fix #12986: Throw descriptive UnsupportedOperationException instead of NPE in MavenSession.lookup() - #13020

Merged
gnodet merged 1 commit into
maven-4.0.xfrom
backport/fix-12986-mavensession-lookup-to-4.0.x
Sep 2, 2026
Merged

gnodet merged 1 commit into
maven-4.0.xfrom
backport/fix-12986-mavensession-lookup-to-4.0.x

Conversation

@gnodet

@gnodet gnodet commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Backport of #12996 to maven-4.0.x.

Summary

  • Adds a checkContainer() null guard to the deprecated MavenSession.lookup(), lookupList(), and lookupMap() methods
  • When PlexusContainer is not injected (Maven 4 default), these methods now throw a descriptive UnsupportedOperationException with a migration message instead of a confusing NullPointerException
  • Adds MavenSessionTest with 7 test cases covering both the null-container (Maven 4) and populated-container (Maven 3) paths

…f NPE in MavenSession.lookup() (#12996)

* Fix #12986: Throw descriptive UnsupportedOperationException instead of NPE in MavenSession.lookup()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add happy-path delegation tests for lookupList and lookupMap

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Fix pre-existing compile error: remove stale PathTranslator reference in DefaultModelBuilderTest

PathTranslator was removed from the public API in MNG-8749 but the test
was not updated. Remove the stale lookup call to match the new
DefaultProfileActivationContext constructor signature.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet added this to the 4.0.0-rc-7 milestone Sep 2, 2026
@gnodet gnodet added the bug Something isn't working label Sep 2, 2026
@gnodet gnodet self-assigned this Sep 2, 2026

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Clean backport of #12996 to maven-4.0.x. The core MavenSession null-guard changes (checkContainer() + 4 lookup guards) and the new MavenSessionTest (9 test cases) are identical to the original. The one excluded hunk (DefaultModelBuilderTest.java — PathTranslator removal) is correctly omitted because maven-4.0.x still uses the old DefaultProfileActivationContext constructor that accepts PathTranslator (removed on master by MNG-8749). All 24 CI checks pass. LGTM.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

gnodet added a commit to gnodet/maven that referenced this pull request Sep 2, 2026
@gnodet
gnodet merged commit 20c5983 into maven-4.0.x Sep 2, 2026
43 of 44 checks passed
@gnodet
gnodet deleted the backport/fix-12986-mavensession-lookup-to-4.0.x branch September 2, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant