[ 
https://issues.apache.org/jira/browse/MNG-7834?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17739859#comment-17739859
 ] 

ASF GitHub Bot commented on MNG-7834:
-------------------------------------

gnodet commented on code in PR #1195:
URL: https://github.com/apache/maven/pull/1195#discussion_r1251743128


##########
src/mdo/model-v3.vm:
##########
@@ -201,18 +201,27 @@ public class ${class.name}
         if (!Objects.equals(map, getDelegate().get${cap}())) {
             update(getDelegate().with${cap}(map));
         }
-      #else
+      #elseif ( $field.to != "String" && $field.type == "java.util.List" && 
$field.multiplicity == "*" )
+        if (${field.name} == null) {
+            ${field.name} = Collections.emptyList();
+        }
         if (!Objects.equals(${field.name}, ${pfx}${cap}())) {
-        #if ( $field.to != "String" && $field.type == "java.util.List" && 
$field.multiplicity == "*" )
             update(getDelegate().with${cap}(
-                   ${field.name}.stream().map(c -> 
c.getDelegate()).collect(Collectors.toList())));
+                ${field.name}.stream().map(c -> 
c.getDelegate()).collect(Collectors.toList())));
             ${field.name}.forEach(e -> e.childrenTracking = this::replace);
-        #elseif ( $field.to && $field.to != "String" )
-            update(getDelegate().with${cap}(${field.name}.getDelegate()));
-            ${field.name}.childrenTracking = this::replace;
-        #else
+        }
+      #elseif ( $field.to && $field.to != "String" )
+        if (!Objects.equals(${field.name}, ${pfx}${cap}())){

Review Comment:
   The new code looks like:
   ```
       public void setDistributionManagement(DistributionManagement 
distributionManagement) {
           if (!Objects.equals(distributionManagement, 
getDistributionManagement())){
               if (distributionManagement != null) {
                   
update(getDelegate().withDistributionManagement(distributionManagement.getDelegate()));
                   distributionManagement.childrenTracking = this::replace;
               } else {
                   update(getDelegate().withDistributionManagement(null));
               }
           }
       }
   ```





> NPE in flatten-maven-plugin
> ---------------------------
>
>                 Key: MNG-7834
>                 URL: https://issues.apache.org/jira/browse/MNG-7834
>             Project: Maven
>          Issue Type: Bug
>    Affects Versions: 4.0.0-alpha-7
>            Reporter: Guillaume Nodet
>            Priority: Major
>
> The flatten-maven-plugin fails with a NullPointerException:
> {code}[ERROR] Failed to execute goal 
> org.codehaus.mojo:flatten-maven-plugin:1.5.0:flatten (default-cli) on project 
> camel: failed to create a clean pom: Cannot invoke "java.util.List.stream()" 
> because "dependencies" is null -> [Help 1]
> org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute 
> goal org.codehaus.mojo:flatten-maven-plugin:1.5.0:flatten (default-cli) on 
> project camel: failed to create a clean pom
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:341)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:324)
>       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:77)
>       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:114)
>       at 
> io.takari.maven.builder.smart.SmartBuilderImpl.buildProject(SmartBuilderImpl.java:204)
>       at 
> io.takari.maven.builder.smart.SmartBuilderImpl$ProjectBuildTask.run(SmartBuilderImpl.java:78)
>       at 
> java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
>       at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
>       at 
> java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
>       at 
> java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
>       at java.base/java.lang.Thread.run(Thread.java:1623)
> Caused by: org.apache.maven.plugin.MojoExecutionException: failed to create a 
> clean pom
>       at 
> org.codehaus.mojo.flatten.FlattenMojo.createFlattenedPom(FlattenMojo.java:556)
>       at org.codehaus.mojo.flatten.FlattenMojo.execute(FlattenMojo.java:406)
>       at 
> org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:143)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:336)
>       ... 15 common frames omitted
> Caused by: java.lang.NullPointerException: Cannot invoke 
> "java.util.List.stream()" because "dependencies" is null
>       at org.apache.maven.model.ModelBase.setDependencies(ModelBase.java:164)
>       at 
> org.codehaus.mojo.flatten.FlattenMojo.createCleanPom(FlattenMojo.java:686)
>       at 
> org.codehaus.mojo.flatten.FlattenMojo.createFlattenedPom(FlattenMojo.java:554)
>       ... 18 common frames omitted
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to