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/08/27 01:09:17 UTC

(maven) 01/01: Fix #12832: guard missing project index before auto-unbox NPE in MojoExecutor

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch checkout-12832-can-projectid-have-a-value-which
in repository https://gitbox.apache.org/repos/asf/maven.git

commit f7676fbf8383a39845d151824d71dadb18c777fe
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Aug 27 03:09:03 2026 +0200

    Fix #12832: guard missing project index before auto-unbox NPE in MojoExecutor
    
    In executeForkedExecutions(), projectIndex.getIndices().get(projectId) can
    return null when a forked execution references a project not in the reactor
    (e.g. parallel builds, stale cached index, or extensions modifying session
    projects). The null Integer auto-unboxes to NPE at the int assignment.
    
    Guard both the index and project lookups with null checks, throwing
    LifecycleExecutionException with a clear diagnostic message instead of
    an opaque NullPointerException.
    
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
 .../apache/maven/lifecycle/internal/MojoExecutor.java   | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java
index 92b3f75bee..8490f2fab0 100644
--- a/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java
+++ b/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java
@@ -438,9 +438,24 @@ public List<MavenProject> executeForkedExecutions(MojoExecution mojoExecution, M
                             .getData()
                             .computeIfAbsent(PROJECT_INDEX, () -> new ProjectIndex(session.getProjects()));
 
-                    int index = projectIndex.getIndices().get(projectId);
+                    Integer index = projectIndex.getIndices().get(projectId);
+                    if (index == null) {
+                        throw new LifecycleExecutionException(
+                                "Forked execution references project '" + projectId
+                                        + "' which is not in the reactor. "
+                                        + "This can happen with parallel builds (-T) or when extensions modify the session projects.",
+                                mojoExecution,
+                                session.getCurrentProject());
+                    }
 
                     MavenProject forkedProject = projectIndex.getProjects().get(projectId);
+                    if (forkedProject == null) {
+                        throw new LifecycleExecutionException(
+                                "Forked execution references project '" + projectId
+                                        + "' which could not be found in the project index.",
+                                mojoExecution,
+                                session.getCurrentProject());
+                    }
 
                     forkedProjects.add(forkedProject);