You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2019/08/08 11:31:48 UTC

[sling-org-apache-sling-installer-factory-configuration] branch master updated: SLING-8622 : Incorrect OSGi configuration ID leads to StringIndexOutOfBoundException

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-org-apache-sling-installer-factory-configuration.git


The following commit(s) were added to refs/heads/master by this push:
     new 2aa51f0  SLING-8622 : Incorrect OSGi configuration ID leads to StringIndexOutOfBoundException
2aa51f0 is described below

commit 2aa51f07f0ae0bb6dce5b21e29e5c198396e7b1c
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Aug 8 14:31:33 2019 +0300

    SLING-8622 : Incorrect OSGi configuration ID leads to StringIndexOutOfBoundException
---
 .../configuration/impl/ConfigUpdateHandler.java    | 36 ++++++++++++++--------
 .../impl/ConfigUpdateHandlerTest.java              |  7 +++++
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java b/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
index 64eeca0..ae0dd75 100644
--- a/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
+++ b/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandler.java
@@ -92,26 +92,38 @@ public class ConfigUpdateHandler implements ResourceUpdater {
     }
 
     protected String[] getFactoryPidAndPid(final String alias, final String oldId) {
-        int pos = 0;
         String factoryPid;
         String pid;
-        if(alias != null) {
-
-            while (alias.charAt(pos) == oldId.charAt(pos)) {
-                pos++;
-            }
-            while (alias.charAt(pos - 1) != '.') {
-                pos--;
+        if (alias != null) {
+
+            // special case, oldId is prefix of alias
+            if (alias.startsWith(oldId)) {
+                final int lastDotIndex = oldId.length();
+                final String factoryIdString = alias.substring(0, lastDotIndex + 1); // keep it +1 to have last dot
+                                                                                     // intact so that we always have
+                                                                                     // even dots in the string
+                factoryPid = alias.substring(0, getMiddleDotSplitIndex(factoryIdString));
+                pid = alias.substring(lastDotIndex + 1);
+
+            } else {
+                int pos = 0;
+                while (alias.charAt(pos) == oldId.charAt(pos)) {
+                    pos++;
+                }
+                while (alias.charAt(pos - 1) != '.') {
+                    pos--;
+                }
+                factoryPid = alias.substring(0, pos - 1);
+                pid = oldId.substring(factoryPid.length() + 1);
             }
-
-            factoryPid = alias.substring(0, pos - 1);
-            pid = oldId.substring(factoryPid.length() + 1);
         } else {
             // extract factory id for these cases where alias is not available and factoryId and pid need to be separated from the old id string itself
             //format assumption ::: "factory_pid.factory_pid.pid"
             // split pid with lastIndexOf('.') then remove the duplicate factory_pid part from the remaining string using the middle dot split index
             final int lastDotIndex = oldId.lastIndexOf('.');
-            String factoryIdString = oldId.substring(0,lastDotIndex+1); // keep it +1 to have last dot intact so that we always have even dots in the string
+            final String factoryIdString = oldId.substring(0, lastDotIndex + 1); // keep it +1 to have last dot intact
+                                                                                 // so that we always have even dots in
+                                                                                 // the string
             factoryPid = oldId.substring(0, getMiddleDotSplitIndex(factoryIdString));
             pid = oldId.substring(lastDotIndex+1);
 
diff --git a/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java b/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java
index d2a3dc9..894a290 100644
--- a/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java
+++ b/src/test/java/org/apache/sling/installer/factories/configuration/impl/ConfigUpdateHandlerTest.java
@@ -53,4 +53,11 @@ public class ConfigUpdateHandlerTest {
                 "org.apache.sling.commons.log.LogManager.factory.config.org.apache.sling.commons.log.LogManager.factory.config.3a514ecf-2e1d-4903-bf88-d878360e8ff1",
                 "org.apache.sling.commons.log.LogManager.factory.config", "3a514ecf-2e1d-4903-bf88-d878360e8ff1");
     }
+
+    @Test
+    public void testDuplicateFactoryPID() {
+        checkFactoryPid("a.b.c.MyFactoryConfig.a.b.c.MyFactoryConfig.5a61b4ab-c8c9-4e20-ab3d-b8b7ea12dfca",
+                "a.b.c.MyFactoryConfig.a.b.c.MyFactoryConfig", "a.b.c.MyFactoryConfig",
+                "5a61b4ab-c8c9-4e20-ab3d-b8b7ea12dfca");
+    }
 }