You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/06/22 09:28:43 UTC
(maven) 01/01: Fix NPE in DefaultLookup.lookupOptional() when container returns null
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch bolder-medallion
in repository https://gitbox.apache.org/repos/asf/maven.git
commit f640018d1d9c66c1f8d084a93711e32782a3f3f4
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Jun 22 11:28:28 2026 +0200
Fix NPE in DefaultLookup.lookupOptional() when container returns null
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 <no...@anthropic.com>
---
.../src/main/java/org/apache/maven/internal/impl/DefaultLookup.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLookup.java b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLookup.java
index a5a0f82d94..f800e2e357 100644
--- a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLookup.java
+++ b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLookup.java
@@ -64,7 +64,7 @@ public <T> T lookup(Class<T> type, String name) {
@Override
public <T> Optional<T> lookupOptional(Class<T> type) {
try {
- return Optional.of(container.lookup(type));
+ return Optional.ofNullable(container.lookup(type));
} catch (ComponentLookupException e) {
if (e.getCause() instanceof NoSuchElementException) {
return Optional.empty();
@@ -76,7 +76,7 @@ public <T> Optional<T> lookupOptional(Class<T> type) {
@Override
public <T> Optional<T> lookupOptional(Class<T> type, String name) {
try {
- return Optional.of(container.lookup(type, name));
+ return Optional.ofNullable(container.lookup(type, name));
} catch (ComponentLookupException e) {
if (e.getCause() instanceof NoSuchElementException) {
return Optional.empty();