Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: NPE because declared MavenSession field hides field of superclass #439

Merged
merged 1 commit into from
Aug 11, 2024

Conversation

sebthom
Copy link
Contributor

@sebthom sebthom commented Aug 7, 2024

The exec goal plugin fails an NPE in the latest 3.4.0 release. The reason is that after the code changes of #432 AbstractExecMojo and ExecMojo declare an injectable MavenSession session resulting in one being not populated by Mavens DI.

This PR fixes the issue by removing the redundant session field from the ExecMojo.

The issue does not seem to be reproducible in the integration tests, so I cannot provide a new test case.

Stacktrace:

java.lang.NullPointerException: Cannot invoke "org.apache.maven.execution.MavenSession.getRepositorySession()" because the return value of "org.codehaus.mojo.exec.AbstractExecMojo.getSession()" is null
    at org.codehaus.mojo.exec.AbstractExecMojo.resolveExecutableDependencies (AbstractExecMojo.java:346)
    at org.codehaus.mojo.exec.AbstractExecMojo.determineRelevantPluginDependencies (AbstractExecMojo.java:319)
    at org.codehaus.mojo.exec.ExecMojo.computePath (ExecMojo.java:702)
    at org.codehaus.mojo.exec.ExecMojo.computeClasspathString (ExecMojo.java:676)
    at org.codehaus.mojo.exec.ExecMojo.handleArguments (ExecMojo.java:605)
    at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:391)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    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:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:903)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:280)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:203)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)

@sebthom
Copy link
Contributor Author

sebthom commented Aug 7, 2024

@slawekjaranowski I believe this issue qualifies for a timely 3.4.1 fix release. I would really appreciate if you find the time/capacity to merge and release this soon.

@slawekjaranowski
Copy link
Member

@sebthom - thanks ... it is very strange that no IT detect it ...

@slawekjaranowski
Copy link
Member

@sebthom can you provide a configuration which cause it, we can add such case as IT

@sebthom
Copy link
Contributor Author

sebthom commented Aug 8, 2024

You should be able to reproduce it with an empty maven project using the following pom.xml executing mvn test

<project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>test</groupId>
   <artifactId>issue-439</artifactId>
   <version>0.0.1-SNAPSHOT</version>

   <build>
      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.4.0</version>
            <executions>
               <execution>
                  <phase>test</phase>
                  <goals>
                     <goal>exec</goal>
                  </goals>
                  <configuration>
                     <includePluginDependencies>true</includePluginDependencies>
                     <executableDependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                     </executableDependency>
                     <executable>java</executable>
                     <arguments>
                        <argument>-classpath</argument>
                        <classpath />
                        <argument>org.junit.runner.JUnitCore</argument>
                     </arguments>
                  </configuration>
               </execution>
            </executions>
            <dependencies>
               <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.13.2</version>
               </dependency>
            </dependencies>
         </plugin>
      </plugins>
   </build>
</project>

Interestingly when you remove the section <executableDependency> section it works.

@slawekjaranowski
Copy link
Member

Thanks I will add it as IT tomorrow or at weekend unless you do it 😄
Next I will release a bug fix version

@slawekjaranowski slawekjaranowski added this to the 3.4.1 milestone Aug 9, 2024
@sebthom
Copy link
Contributor Author

sebthom commented Aug 9, 2024

@slawekjaranowski I added the integration test

@slawekjaranowski slawekjaranowski merged commit a8c4f94 into mojohaus:master Aug 11, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants