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 2016/11/05 16:00:14 UTC

svn commit: r1768233 - in /sling/trunk/installer/factories/configuration: pom.xml src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java

Author: cziegeler
Date: Sat Nov  5 16:00:14 2016
New Revision: 1768233

URL: http://svn.apache.org/viewvc?rev=1768233&view=rev
Log:
SLING-6247 : Potential class cast exception for primitive arrays

Modified:
    sling/trunk/installer/factories/configuration/pom.xml
    sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java

Modified: sling/trunk/installer/factories/configuration/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/pom.xml?rev=1768233&r1=1768232&r2=1768233&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/pom.xml (original)
+++ sling/trunk/installer/factories/configuration/pom.xml Sat Nov  5 16:00:14 2016
@@ -48,9 +48,18 @@
                 <extensions>true</extensions>
                 <configuration>
                     <instructions>
+                        <Import-Package>
+                            !org.apache.commons.lang3.builder,
+                            !org.apache.commons.lang3.math,
+                            !org.apache.commons.lang3.mutable,
+                            *
+                        </Import-Package>
                         <Bundle-Activator>
                             org.apache.sling.installer.factories.configuration.impl.Activator
                         </Bundle-Activator>
+                        <Embed-Dependency>
+                            commons-lang3;inline="org/apache/commons/lang3/ArrayUtils.*"
+                        </Embed-Dependency>
                     </instructions>
                 </configuration>
             </plugin>
@@ -82,6 +91,12 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.5</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.installer.core</artifactId>
             <version>3.7.1-SNAPSHOT</version>

Modified: sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java?rev=1768233&r1=1768232&r2=1768233&view=diff
==============================================================================
--- sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java (original)
+++ sling/trunk/installer/factories/configuration/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigUtil.java Sat Nov  5 16:00:14 2016
@@ -25,6 +25,7 @@ import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Set;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
@@ -73,6 +74,35 @@ abstract class ConfigUtil {
         return keys;
     }
 
+    /**
+     * Convert the object to an array
+     * @param value The array
+     * @return an object array
+     */
+    private static Object[] convertToObjectArray(final Object value) {
+        final Object[] values;
+        if (value instanceof long[]) {
+            values = ArrayUtils.toObject((long[])value);
+        } else if (value instanceof int[]) {
+            values = ArrayUtils.toObject((int[])value);
+        } else if (value instanceof double[]) {
+            values = ArrayUtils.toObject((double[])value);
+        } else if (value instanceof byte[]) {
+            values = ArrayUtils.toObject((byte[])value);
+        } else if (value instanceof float[]) {
+            values = ArrayUtils.toObject((float[])value);
+        } else if (value instanceof short[]) {
+            values = ArrayUtils.toObject((short[])value);
+        } else if (value instanceof boolean[]) {
+            values = ArrayUtils.toObject((boolean[])value);
+        } else if (value instanceof char[]) {
+            values = ArrayUtils.toObject((char[])value);
+        } else {
+            values = (Object[]) value;
+        }
+        return values;
+    }
+
     /** True if a and b represent the same config data, ignoring "non-configuration" keys in the dictionaries */
     public static boolean isSameData(Dictionary<String, Object>a, Dictionary<String, Object>b) {
         boolean result = false;
@@ -85,8 +115,8 @@ abstract class ConfigUtil {
                     final Object valA = a.get(key);
                     final Object valB = b.get(key);
                     if ( valA.getClass().isArray() ) {
-                        final Object[] arrA = (Object[])valA;
-                        final Object[] arrB = (Object[])valB;
+                        final Object[] arrA = convertToObjectArray(valA);
+                        final Object[] arrB = convertToObjectArray(valB);
 
                         if ( arrA.length != arrB.length ) {
                             result = false;