[Backport 4.0.x] Fix NPE in DefaultLookup.lookupOptional() when container returns null - #12340
Merged
Merged
Conversation
…#12336) PlexusContainer.lookup() can return null instead of throwing ComponentLookupException. Using Optional.of(null) causes a NullPointerException. Use Optional.ofNullable() instead so that a null lookup result is correctly represented as Optional.empty(). This fixes maven-jdeprscan-plugin integration tests (list-default, list-forremoval) which fail on Maven 4.0.x because DefaultToolchainManager.retrieveContext() calls lookupOptional(Project.class) and the container returns null. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
ascheman
added a commit
to aschemaven/maven
that referenced
this pull request
Jun 28, 2026
The backported NPE fix for DefaultLookup.lookupOptional (apache#12340) — switching Optional.of to Optional.ofNullable so a null component lookup returns an empty Optional instead of throwing NullPointerException — shipped without a regression test. Add DefaultLookupTest in maven-core covering both lookupOptional overloads: null component -> empty Optional (the guarded NPE case), present component -> value, and a ComponentLookupException whose cause is NoSuchElementException -> empty. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ascheman
added a commit
to aschemaven/maven
that referenced
this pull request
Jul 3, 2026
The backported NPE fix for DefaultLookup.lookupOptional (apache#12340) — switching Optional.of to Optional.ofNullable so a null component lookup returns an empty Optional instead of throwing NullPointerException — shipped without a regression test. Add DefaultLookupTest in maven-core covering both lookupOptional overloads across four scenarios: null component -> empty Optional (the guarded NPE case), present component -> value, ComponentLookupException caused by NoSuchElementException -> empty, and any other cause -> rethrown as LookupException. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gnodet
pushed a commit
that referenced
this pull request
Jul 7, 2026
The backported NPE fix for DefaultLookup.lookupOptional (#12340) — switching Optional.of to Optional.ofNullable so a null component lookup returns an empty Optional instead of throwing NullPointerException — shipped without a regression test. Add DefaultLookupTest in maven-core covering both lookupOptional overloads across four scenarios: null component -> empty Optional (the guarded NPE case), present component -> value, ComponentLookupException caused by NoSuchElementException -> empty, and any other cause -> rethrown as LookupException. Co-authored-by: Gerd Aschemann <ascheman@apache.org> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #12336 to
maven-4.0.x.Cherry-pick of 712b5c0 — clean, no conflicts.
Summary
PlexusContainer.lookup()can returnnullinstead of throwingComponentLookupException.DefaultLookup.lookupOptional()wraps the result withOptional.of(), which throwsNullPointerExceptionon null input. Changed toOptional.ofNullable()so a null result is correctly represented asOptional.empty().maven-jdeprscan-pluginintegration tests (list-default,list-forremoval) which fail on Maven 4.0.x becauseDefaultToolchainManager.retrieveContext()callslookupOptional(Project.class)and the container returns null.