Skip to content

NullPointerException in DefaultThirdPartyTool#getProjectsWithNoLicense(...) after upgrade from 2.1.0 to 2.2.0 #508

Closed

Description

@rzo1

Hi,

we are trying to upgrade from 2.1.0 to 2.2.0 in our project.

Currently, we use

mvn license:aggregate-add-third-party@generate-and-check-licenses -Dlicense.skipAggregateAddThirdParty=false -Dlicense.thirdPartyFilename=DEPENDENCY-LICENSES -Dlicense.outputDirectory=target

in a CI env with a config as follows

   <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>license-maven-plugin</artifactId>
                        <inherited>false</inherited>
                        <configuration>
                            <missingFile>${project.basedir}/THIRD-PARTY.properties</missingFile>
                            <aggregateMissingLicensesFile>${project.basedir}/THIRD-PARTY.properties</aggregateMissingLicensesFile>
                        </configuration>
                        <executions>
                            <execution>
                                <id>generate-and-check-licenses</id>
                                <goals>
                                    <goal>aggregate-add-third-party</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>download-licenses</id>
                                <goals>
                                    <goal>aggregate-download-licenses</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

and

   <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>license-maven-plugin</artifactId>
                    <version>${maven.mojo.license.plugin}</version>
                    <configuration>
                        <useMissingFile>true</useMissingFile>
                        <failOnMissing>true</failOnMissing>
                        <includeTransitiveDependencies>true</includeTransitiveDependencies>
                        <fileTemplate>/org/codehaus/mojo/license/third-party-file-groupByMultiLicense.ftl
                        </fileTemplate>
                        <excludedScopes>system,test</excludedScopes>
                        <excludedGroups>${project.groupId}</excludedGroups>
                        <licenseMerges>
                            <licenseMerge>
                                Apache License, Version 2.0 |
                                Apache License, version 2.0 |
                                Apache License Version 2 |
                                Apache License Version 2.0 |
                                Apache License version 2.0 |
                                Apache 2 |
                                Apache 2.0 |
                                Apache License, 2.0 |
                                Apache License 2 |
                                Apache License 2.0 |
                                Apache Public License 2.0 |
                                Apache Software License - Version 2.0 |
                                Apache v2 |
                                ASL, version 2 |
                                The Apache License, Version 2.0 |
                                The Apache Software License, Version 2.0
                            </licenseMerge>
                            <licenseMerge>
                                Apache License |
                                Apache Software Licenses
                            </licenseMerge>
                            <licenseMerge>
                                BSD License |
                                BSD license |
                                BSD |
                                The BSD License
                            </licenseMerge>
                            <licenseMerge>
                                BSD 3-Clause License |
                                BSD 3-Clause |
                                BSD 3-clause |
                                The BSD 3-Clause License |
                                New BSD License |
                                New BSD license
                            </licenseMerge>
                            <licenseMerge>
                                Common Development and Distribution License (CDDL) v1.0 |
                                COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 |
                                CDDL 1.0
                            </licenseMerge>
                            <licenseMerge>
                                Common Development and Distribution License (CDDL) v1.1 |
                                COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.1 |
                                CDDL 1.1 |
                                Common Development and Distribution License (CDDL), Version 1.1
                            </licenseMerge>
                            <licenseMerge>
                                Common Development and Distribution License |
                                <!-- Multilicense, choosing CDDL -->
                                CDDL+GPL |
                                CDDL+GPL License |
                                CDDL + GPLv2 with classpath exception
                            </licenseMerge>
                            <licenseMerge>
                                Eclipse Public License, Version 1.0 |
                                Eclipse Public License 1.0 |
                                Eclipse Public License - v 1.0
                            </licenseMerge>
                            <licenseMerge>
                                Eclipse Public License, Version 2.0 |
                                EPL-2.0 |
                                EPL 2.0
                            </licenseMerge>
                            <licenseMerge>
                                Eclipse Distribution License, Version 1.0 |
                                Eclipse Distribution License - v 1.0 |
                                EDL 1.0
                            </licenseMerge>
                            <licenseMerge>
                                MIT License |
                                The MIT License |
                                MIT license |
                                MIT X11 License |
                                MIT
                            </licenseMerge>
                            <licenseMerge>
                                The GNU General Public License (GPL), Version 2, With Classpath Exception |
                                GPL2 w/ CPE
                            </licenseMerge>
                            <licenseMerge>
                                GNU Lesser General Public License (LGPL), Version 2.1 |
                                LGPL, version 2.1 |
                                GNU Lesser General Public License Version 2.1 |
                                GNU Lesser General Public License, version 2.1
                            </licenseMerge>
                            <licenseMerge>
                                Common Public License Version 1.0 |
                                Common Public License - v 1.0
                            </licenseMerge>
                        </licenseMerges>
                    </configuration>
                </plugin>

This works fine with 2.1.0 but now fails with a NullPointerException in 2.2.0:

[ERROR] Failed to execute goal org.codehaus.mojo:license-maven-plugin:2.2.0:aggregate-add-third-party (generate-and-check-licenses) on project XXX could not execute goal AggregatorAddThirdPartyMojo for reason : null: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:license-maven-plugin:2.2.0:aggregate-add-third-party (generate-and-check-licenses) on project XXX: could not execute goal AggregatorAddThirdPartyMojo for reason : null
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:375)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:298)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    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)
Caused by: org.apache.maven.plugin.MojoExecutionException: could not execute goal AggregatorAddThirdPartyMojo for reason : null
    at org.codehaus.mojo.license.AbstractLicenseMojo.execute (AbstractLicenseMojo.java:187)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:298)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    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)
Caused by: java.lang.NullPointerException
    at org.codehaus.mojo.license.api.DefaultThirdPartyTool.getProjectsWithNoLicense (DefaultThirdPartyTool.java:168)
    at org.codehaus.mojo.license.api.DefaultThirdPartyHelper.getProjectsWithNoLicense (DefaultThirdPartyHelper.java:214)
    at org.codehaus.mojo.license.AbstractAddThirdPartyMojo.consolidate (AbstractAddThirdPartyMojo.java:775)
    at org.codehaus.mojo.license.AddThirdPartyMojo.initFromMojo (AddThirdPartyMojo.java:440)
    at org.codehaus.mojo.license.AggregatorAddThirdPartyMojo.doAction (AggregatorAddThirdPartyMojo.java:221)
    at org.codehaus.mojo.license.AbstractLicenseMojo.execute (AbstractLicenseMojo.java:180)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:298)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    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] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Obviously, after looking into the code it seems that licenseMap is NULL.

Any idea what I am missing here or anything we are doing wrong in the related config?

Thanks in advance!

Activity

  1. added
    bug
    on Jul 4, 2023
  2. slawekjaranowski commented on Jul 4, 2023

    @slawekjaranowski
    Member

    Can you provide a simple project which reproduce issue.
    We can add such project to IT in order to be sure with next changes.

    Something like in https://github.com/mojohaus/license-maven-plugin/tree/master/src/it

  3. rzo1 commented on Jul 4, 2023

    @rzo1
    Author

    Tried fiddling around to produce a minimal reproducer but failed to build one. It seems, that it is bit tricky to reproduce.

    From mvnDebug it seems, that there are two executions involved. The first one correctly populates the licenseMap, in the second phase, we are running into an early return in

    https://github.com/mojohaus/license-maven-plugin/blob/master/src/main/java/org/codehaus/mojo/license/AbstractAddThirdPartyMojo.java#L736

    which leaves the licenseMap uninitalized (=null). This is confirmed by doing a git bisect, which leads to 1c8fab2

    For completeness, I added the full plugin config in the entry post.

    I will try building an IT for it, if I find some more time this week.

  4. slawekjaranowski commented on Jul 4, 2023

    @slawekjaranowski
    Member

    It can be my fault ... 😄
    I was assume that we not need more computation if plugin should skip executions ...
    But looks like aggregate goal do something more in some cases ....

  5. rzo1 commented on Jul 4, 2023

    @rzo1
    Author

    Did some more debugging :-)

    A workaround would be to use -Dlicense.force=true.

    The skip condition is meet due to the following change from

         long buildTimestamp = getBuildTimestamp();
    
            LOG.debug( "Build start   at: {}", buildTimestamp );
            LOG.debug( "third-party file: {}", thirdPartyFile.lastModified() );
    
            doGenerate = force || !thirdPartyFile.exists() || buildTimestamp > thirdPartyFile.lastModified();
    

    to

       File projectFile = project.getFile() != null ? project.getFile() : new File("");
    
            LOG.debug( "project file: {} last modified: {}", projectFile, projectFile.lastModified() );
            LOG.debug( "third-party file: {} last modified: {}", thirdPartyFile, thirdPartyFile.lastModified() );
    
            doGenerate = force || !thirdPartyFile.exists() || projectFile.lastModified() > thirdPartyFile.lastModified();
    

    In the 2nd execution, projectFile.lastModified() > thirdPartyFile.lastModified() is false, the thirdPartyFile exists and doGenerate will be false, so we are hitting the skip condition later running into the NPE.

    I guess, that this was an optimization to avoid regeneration if the actual project file wasn't modified?

  6. slawekjaranowski commented on Jul 5, 2023

    @slawekjaranowski
    Member

    There is some magic in code ... in aggregate goal method initFromMojo is called for each child ... such code can be refactored but it is another issue.

    There is isAggregatorBuild field - it should be moved to AbstractAddThirdPartyMojo or used as parameter for AbstractAddThirdPartyMojo#init and used in condition for check if mojo should be executed.

    By the way I still can not reproduce even execute many times ....

    I will prepare a fix.

  7. added 4 commits that reference this issue on Jul 5, 2023
  8. rzo1 commented on Jul 5, 2023

    @rzo1
    Author
  9. added a commit that references this issue on Jul 18, 2023
  10. slawekjaranowski commented on Jul 18, 2023

    @slawekjaranowski
    Member
  11. rzo1 commented on Jul 18, 2023

    @rzo1
    Author

    @slawekjaranowski Yeah, I didn't get the IT failing either :/

    The setup is basically similar to https://github.com/rzo1/license-maven-plugin-508 - the only real difference is the pre-existing DEPENDENCY-LICENSES in the root directory. This is also similar to the setup they have in https://github.com/camunda/connector-sdk/pull/510 were they also encountered the issue.

    Therefore, I guess, that the pre-existing file plays a role. For testing, I added it to the IT with similar results: IT passes :/

  12. slawekjaranowski commented on Jul 18, 2023

    @slawekjaranowski
    Member

    @rzo1 - I have a reproduce 😄

  13. added a commit that references this issue on Jul 23, 2023
    85ac3b0
  14. rzo1 commented on Jul 23, 2023

    @rzo1
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions