Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-6921

Maven compile with properties ${artifactId} and ${project.build.finalName} occurs java.lang.NullPointerException

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.6.2, 3.6.3
    • 3.8.2, 4.0.0-alpha-2, 4.0.0
    • Command Line
    • MacOS 10.15.2

    Description

      with maven 3.3.9,this project with command "mvn compile" can process normally,but NPE when change to 3.6.3

      after debug :

      ${artifactId} and ${project.build.finalName} define at same time will cause InterpolationCycleException

      PS: ${project.build.finalName} will be parse to ${project.artifactId}-${project.version} with default config.

      this problem can replay with attach project

      Caused by: java.lang.NullPointerException
          at java.util.concurrent.ConcurrentHashMap$MapEntry.setValue (ConcurrentHashMap.java:3539)
          at org.apache.maven.model.interpolation.StringVisitorModelInterpolator$ModelVisitor.visit (StringVisitorModelInterpolator.java:1429)
          at org.apache.maven.model.interpolation.StringVisitorModelInterpolator$ModelVisitor.visit (StringVisitorModelInterpolator.java:1027)
          at org.apache.maven.model.interpolation.StringVisitorModelInterpolator$ModelVisitor.visit (StringVisitorModelInterpolator.java:170)
          at org.apache.maven.model.interpolation.StringVisitorModelInterpolator.interpolateModel (StringVisitorModelInterpolator.java:107)
          at org.apache.maven.model.building.DefaultModelBuilder.interpolateModel (DefaultModelBuilder.java:789)
          at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:393)
          at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:448)
          at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:414)
          at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:558)
          at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:414)
          at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:377)
          at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:414)
          at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:405)
          at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:82)
          at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:507)
          at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:219)
          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:957)
          at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
          at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
          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:567)
          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)

       

      pom.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <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>
          <parent>
              <groupId>com.example</groupId>
              <artifactId>maven-demo</artifactId>
              <version>0.0.1-SNAPSHOT</version>
          </parent>
      
          <version>0.0.1-SNAPSHOT</version>
          <name>maven-demo-api</name>
          <description>Demo project for Maven</description>
          <packaging>jar</packaging>
      
          <properties>
              <groupId>com.example</groupId>
              <artifactId>maven-demo-api</artifactId>
              <project.build.finalName>maven-demo-api</project.build.finalName>
              <finalName>${project.build.finalName}</finalName>
          </properties>
          <artifactId>${artifactId}</artifactId>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-maven-plugin</artifactId>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-jar-plugin</artifactId>
                      <version>2.3.2</version>
                      <configuration>
                          <finalName>${finalName}</finalName>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
      </project>
      
      

      org.apache.maven.model.interpolation.StringVisitorModelInterpolator#visit

      private void visit( Properties properties )
      {
          if ( properties != null )
          {
              for ( Map.Entry<Object, Object> entry : properties.entrySet() )
              {
                  Object v = entry.getValue();
                  if ( v instanceof String )
                  {
                      String value = (String) v;
                      String inter = interpolate( value ); // inter can be return null
                      if ( value != inter )
                      {
                          entry.setValue( inter );
                      }
                  }
              }
          }
      }
      

      Attachments

        1. maven-demo.zip
          13 kB
          anruence

        Issue Links

          Activity

            People

              slachiewicz Sylwester Lachiewicz
              anruence anruence
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: