sebtiem opened a new issue, #14123:
URL: https://github.com/apache/maven/issues/14123

   ### Affected version
   
   master
   
   ### Bug description
   
   ### Affected version
   
   4.2.0-SNAPSHOT (master 41394fa)
   
   ### Reproduction
   
   Will be added after issue creation.
   
   ### Bug description
   
   Invoking an aggregator goal (`aggregator = true`) on the command line, 
without any lifecycle phase, in a multi-module reactor fails with `-b 
concurrent` before any goal runs:
   
   ```
   [ERROR] Cannot invoke "java.util.Map.put(Object, Object)" because the return 
value of "java.util.Map.get(Object)" is null
   java.lang.NullPointerException: Cannot invoke "java.util.Map.put(Object, 
Object)" because the return value of "java.util.Map.get(Object)" is null
           at 
org.apache.maven.lifecycle.internal.concurrent.BuildPlan.addStep(BuildPlan.java:71)
           at 
org.apache.maven.lifecycle.internal.concurrent.BuildPlanExecutor$BuildContext.lambda$buildInitialPlan$5(BuildPlanExecutor.java:368)
           at 
java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
           at 
java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:807)
           at 
org.apache.maven.lifecycle.internal.concurrent.BuildPlanExecutor$BuildContext.buildInitialPlan(BuildPlanExecutor.java:368)
           at 
org.apache.maven.lifecycle.internal.concurrent.BuildPlanExecutor$BuildContext.<init>(BuildPlanExecutor.java:289)
           at 
org.apache.maven.lifecycle.internal.concurrent.BuildPlanExecutor.execute(BuildPlanExecutor.java:232)
           at 
org.apache.maven.lifecycle.internal.concurrent.ConcurrentLifecycleStarter.execute(ConcurrentLifecycleStarter.java:108)
           at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:333)
           at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:232)
           at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
           at 
org.apache.maven.cling.invoker.mvn.MavenInvoker.doExecute(MavenInvoker.java:567)
           at 
org.apache.maven.cling.invoker.mvn.MavenInvoker.execute(MavenInvoker.java:104)
           at 
org.apache.maven.cling.invoker.mvn.MavenInvoker.execute(MavenInvoker.java:88)
           at 
org.apache.maven.cling.invoker.LookupInvoker.doInvoke(LookupInvoker.java:199)
           at 
org.apache.maven.cling.invoker.LookupInvoker.invoke(LookupInvoker.java:143)
           at org.apache.maven.cling.ClingSupport.run(ClingSupport.java:76)
           at org.apache.maven.cling.MavenCling.main(MavenCling.java:73)
           at 
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
           at java.base/java.lang.reflect.Method.invoke(Method.java:565)
           at 
org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:256)
           at 
org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:210)
           at 
org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:343)
           at 
org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:307)
   ```
   
   **Steps to reproduce**
   
   1. A reactor with a root project and two child modules `a` and `b`.
   2. A plugin with a goal declared as `@Mojo(name = "aggregator-probe", 
aggregator = true)`.
   3. Run `mvn -b concurrent -T2 
<groupId>:<artifactId>:<version>:aggregator-probe`.
   
   Expected: the goal runs once, on the root project, and the build succeeds.
   Actual: `NullPointerException` in `BuildPlan.addStep()` 
(`BuildPlan.java:71`).
   
   Adding any lifecycle phase in front of the goal (for example `mvn -b 
concurrent validate <goal>`) avoids the failure.
   
   **Cause**
   
   `DefaultLifecycleTaskSegmentCalculator` puts the goal into an aggregating 
task segment. In `BuildPlanExecutor.BuildContext.buildInitialPlan()`, the 
`BuildPlan` is created with all reactor projects, but an aggregating segment is 
calculated for the root project only, so after `plan.then(segment)` the plan 
map contains only the root project.
   
   The loop that creates the `$plan$`, setup and teardown steps then iterates 
over all reactor projects:
   
   ```java
   for (MavenProject project : plan.getAllProjects().keySet()) {
       ...
       Stream.of(pplan, setup, teardown).forEach(step -> plan.addStep(project, 
step.name, step));
   }
   ```
   
   `BuildPlan.steps(project)` handles a project without an entry in the plan 
map, but `BuildPlan.addStep()` does not (`plan.get(project).put(...)`), so it 
throws for the first child module.
   
   When a non-aggregating segment is part of the same build, every project has 
an entry in the plan map, which is why adding a phase hides the problem.
   
   **Related**
   
   - #14120 / #14121: same loop in `buildInitialPlan()`, different problem. A 
goal invoked alone is both the first and last step of its project, and teardown 
does not wait for it. Once this NPE is fixed, an aggregator goal invoked alone 
runs into that case as well.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to