[ https://issues.apache.org/jira/browse/MNG-7679?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17686781#comment-17686781 ]
Hans Aikema commented on MNG-7679: ---------------------------------- In my view the root cause is in an improper return for org.apache.maven.project.MavenProject#getCollectedProjects. I am surprised to see that a List-typed return variable is allowed to be null. In my view it should return an empty list if collectedProjects is null (or maybe even collectedProjects should be initialised as an empty arraylist) > [REGRESSION] Build fails when executing a single mojo without a POM > ------------------------------------------------------------------- > > Key: MNG-7679 > URL: https://issues.apache.org/jira/browse/MNG-7679 > Project: Maven > Issue Type: Bug > Components: Core > Affects Versions: 3.8.x-candidate, 3.9.0, 3.9.1-candidate, 4.0.0-alpha-4 > Environment: Linux, MacOS, Windows > Reporter: Alexey Venderov > Assignee: Guillaume Nodet > Priority: Major > Fix For: 4.0.0-alpha-5, 3.8.8, 3.9.1 > > > Hi, > > When invoking a single mojo, for example, {{{}install:install-file{}}}, > outside of the project directory (no pom in the directory), then the build is > failing with {{{}NullPointerException{}}}. > > Steps to reproduce: > # Download maven 3.9: > [https://dlcdn.apache.org/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.zip] > # Unzip it to any directory > # Create a simple text file {{echo "foo" > foo.txt}} > # Try to install {{foo.txt}} into the local repository: > {{./apache-maven-3.9.0/bin/mvn install:install-file -Dfile=foo.txt > -DgroupId=com.example -DartifactId=foo -Dversion=1.0.0 -Dpackaging=jar -X}} > Build fails with the {{{}NullPointerException{}}}: > > {code:java} > [INFO] > ------------------------------------------------------------------------ > [INFO] BUILD FAILURE > [INFO] > ------------------------------------------------------------------------ > [INFO] Total time: 0.086 s > [INFO] Finished at: 2023-02-06T11:48:49+01:00 > [INFO] > ------------------------------------------------------------------------ > [ERROR] NullPointerException > java.lang.NullPointerException > at > org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getProjectAndSubModules > (LifecycleDependencyResolver.java:102) > at > org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getProjects > (LifecycleDependencyResolver.java:93) > at > org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved > (MojoExecutor.java:395) > at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute > (MojoExecutor.java:327) > at org.apache.maven.lifecycle.internal.MojoExecutor.execute > (MojoExecutor.java:213) > at org.apache.maven.lifecycle.internal.MojoExecutor.execute > (MojoExecutor.java:175) > at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 > (MojoExecutor.java:76) > at org.apache.maven.lifecycle.internal.MojoExecutor$1.run > (MojoExecutor.java:163) > at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute > (DefaultMojosExecutionStrategy.java:39) > at org.apache.maven.lifecycle.internal.MojoExecutor.execute > (MojoExecutor.java:160) > at > org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject > (LifecycleModuleBuilder.java:105) > at > org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject > (LifecycleModuleBuilder.java:73) > at > org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build > (SingleThreadedBuilder.java:53) > at org.apache.maven.lifecycle.internal.LifecycleStarter.execute > (LifecycleStarter.java:118) > at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:260) > at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:172) > at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:100) > at org.apache.maven.cli.MavenCli.execute (MavenCli.java:821) > at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:270) > at org.apache.maven.cli.MavenCli.main (MavenCli.java:192) > at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) > at jdk.internal.reflect.NativeMethodAccessorImpl.invoke > (NativeMethodAccessorImpl.java:62) > at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke > (DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke (Method.java:566) > at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced > (Launcher.java:282) > at org.codehaus.plexus.classworlds.launcher.Launcher.launch > (Launcher.java:225) > at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode > (Launcher.java:406) > at org.codehaus.plexus.classworlds.launcher.Launcher.main > (Launcher.java:347) > [ERROR] > {code} > > The same operation is successful when using maven 3.8.7 or earlier: > {code:java} > 🕙 11:56:50 ➜ mvn --version > Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29) > Maven home: /Users/avenderov/.sdkman/candidates/maven/current > Java version: 11.0.17, vendor: Azul Systems, Inc., runtime: > /Users/avenderov/.asdf/installs/java/zulu-11.60.19/zulu-11.jdk/Contents/Home > Default locale: en_DE, platform encoding: UTF-8 > OS name: "mac os x", version: "12.6.3", arch: "aarch64", family: "mac" > ~/tmp/maven-npe 250ms > 🕙 11:56:54 ➜ mvn install:install-file -Dfile=foo.txt -DgroupId=com.example > -DartifactId=foo -Dversion=1.0.0 -Dpackaging=jar > [INFO] Scanning for projects... > [INFO] > [INFO] ------------------< org.apache.maven:standalone-pom > >------------------- > [INFO] Building Maven Stub Project (No POM) 1 > [INFO] --------------------------------[ pom > ]--------------------------------- > [INFO] > [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ > standalone-pom --- > [INFO] Installing /Users/avenderov/tmp/maven-npe/foo.txt to > /Users/avenderov/.m2/repository/com/example/foo/1.0.0/foo-1.0.0.jar > [INFO] > ------------------------------------------------------------------------ > [INFO] BUILD SUCCESS > [INFO] > ------------------------------------------------------------------------ > [INFO] Total time: 0.152 s > [INFO] Finished at: 2023-02-06T11:57:12+01:00 > [INFO] > ------------------------------------------------------------------------ > {code} > > It's also possible to reproduce the issue with the development version of > maven. > # Checkout maven sources. > # Build a new distribution from {{{}master{}}}: {{mvn > -DdistributionTargetDir="$HOME/tmp/maven-npe/apache-maven-4.0.x-SNAPSHOT" > clean package}} > # Repeat steps 3 and 4 from the instruction above. The build fails with the > {{NullPointerException}} > > The issue was introduced with the changes from this ticket: > https://issues.apache.org/jira/browse/MNG-7672. I tried to build a > distribution from this commit > {{[https://github.com/apache/maven/commit/4a3c201bfc9ae492c35e300177d950c10e788bd3]}} > and it works as expected (the same applies for other branches, > {{maven-3.9.x}} and {{{}master{}}}): > {code:java} > 12:18:03 ➜ ./apache-maven-3.8.x-SNAPSHOT/bin/mvn --version > Apache Maven 3.8.8-SNAPSHOT (4a3c201bfc9ae492c35e300177d950c10e788bd3) > Maven home: /Users/avenderov/tmp/maven-npe/apache-maven-3.8.x-SNAPSHOT > Java version: 11.0.17, vendor: Azul Systems, Inc., runtime: > /Users/avenderov/.asdf/installs/java/zulu-11.60.19/zulu-11.jdk/Contents/Home > Default locale: en_DE, platform encoding: UTF-8 > OS name: "mac os x", version: "12.6.3", arch: "aarch64", family: "mac" > ~/tmp/maven-npe 359ms > 🕙 12:18:16 ➜ ./apache-maven-3.8.x-SNAPSHOT/bin/mvn install:install-file > -Dfile=foo.txt -DgroupId=com.example -DartifactId=foo -Dversion=1.0.0 > -Dpackaging=jar > [INFO] Scanning for projects... > [INFO] > [INFO] ------------------< org.apache.maven:standalone-pom > >------------------- > [INFO] Building Maven Stub Project (No POM) 1 > [INFO] --------------------------------[ pom > ]--------------------------------- > [INFO] > [INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ > standalone-pom --- > [INFO] Installing /Users/avenderov/tmp/maven-npe/foo.txt to > /Users/avenderov/.m2/repository/com/example/foo/1.0.0/foo-1.0.0.jar > [INFO] > ------------------------------------------------------------------------ > [INFO] BUILD SUCCESS > [INFO] > ------------------------------------------------------------------------ > [INFO] Total time: 0.150 s > [INFO] Finished at: 2023-02-06T12:18:32+01:00 > [INFO] > ------------------------------------------------------------------------ > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)