This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new fa937a1  Minor code fix
fa937a1 is described below

commit fa937a191f0dda342298ca1f460642781953191a
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Oct 5 13:42:20 2022 +0200

    Minor code fix
---
 .../org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java
index ff5ce24..6f0b834 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/UpdateVersionsMojo.java
@@ -489,6 +489,8 @@ public class UpdateVersionsMojo extends 
AbstractIncludingFeatureMojo {
             } else {
                 container = 
rawFeature.getExtensions().getByName(update.extension.getName()).getArtifacts();
             }
+            final int pos = container.indexOf(update.artifact);
+            final Artifact oldArtifact = pos == -1 ? null : container.get(pos);
             if (!container.removeExact(update.artifact.getId())) {
                 // check if property is used
                 final Artifact same = 
container.getSame(update.artifact.getId());
@@ -518,9 +520,7 @@ public class UpdateVersionsMojo extends 
AbstractIncludingFeatureMojo {
                 }
                 iter.remove();
             } else {
-                // the artifact exists in the container (removeExact returned 
true)
-                final int pos = container.indexOf(update.artifact);
-                final Artifact oldArtifact = container.get(pos);
+                // oldArtifact is not null (removeExact returned true)
                 final Artifact newArtifact = new 
Artifact(update.artifact.getId().changeVersion(update.newVersion));
                 newArtifact.getMetadata().putAll(oldArtifact.getMetadata());
                 container.add(pos, newArtifact);

Reply via email to