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 2013/10/04 07:54:41 UTC

svn commit: r1529082 - in /sling/trunk/bundles/jcr/resource: pom.xml src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java

Author: cziegeler
Date: Fri Oct  4 05:54:41 2013
New Revision: 1529082

URL: http://svn.apache.org/r1529082
Log:
SLING-3140 : ClassCastException while serializing byte[] in Sling Job with JCR Resource Resolver. Apply patch from Tommaso Teofili

Added:
    sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java   (with props)
Modified:
    sling/trunk/bundles/jcr/resource/pom.xml
    sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java

Modified: sling/trunk/bundles/jcr/resource/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/pom.xml?rev=1529082&r1=1529081&r2=1529082&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/pom.xml (original)
+++ sling/trunk/bundles/jcr/resource/pom.xml Fri Oct  4 05:54:41 2013
@@ -191,9 +191,15 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-           <groupId>commons-collections</groupId>
-           <artifactId>commons-collections</artifactId>
-           <version>3.2.1</version>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <version>3.2.1</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.2</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java?rev=1529082&r1=1529081&r2=1529082&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java (original)
+++ sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java Fri Oct  4 05:54:41 2013
@@ -28,6 +28,7 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 
 public class JcrPropertyMapCacheEntry {
@@ -91,7 +92,7 @@ public class JcrPropertyMapCacheEntry {
         this.defaultValue = value;
         if ( value.getClass().isArray() ) {
             this.isMulti = true;
-            final Object[] values = (Object[])value;
+            final Object[] values = convertToObject(value);;
             this.values = new Value[values.length];
             for(int i=0; i<values.length; i++) {
                 this.values[i] = this.createValue(values[i], session);
@@ -108,6 +109,32 @@ public class JcrPropertyMapCacheEntry {
         }
     }
 
+    private Object[] convertToObject(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 long[]) {
+            values = ArrayUtils.toObject((long[])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;
+    }
+
     public Object getDefaultValue() throws RepositoryException {
         return this.defaultValue != null ? this.defaultValue : JcrResourceUtil.toJavaObject(property);
     }

Added: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java?rev=1529082&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java (added)
+++ sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java Fri Oct  4 05:54:41 2013
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.resource.internal.helper;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+/**
+ * Testcase for {@link JcrPropertyMapCacheEntry}
+ */
+public class JcrPropertyMapCacheEntryTest {
+
+    @Test
+    public void testByteArray() throws Exception {
+        assertNotNull(new JcrPropertyMapCacheEntry(new Byte[0], null));
+        assertNotNull(new JcrPropertyMapCacheEntry(new byte[0], null));
+    }
+
+    @Test
+    public void testShortArray() throws Exception {
+        assertNotNull(new JcrPropertyMapCacheEntry(new Short[0], null));
+        assertNotNull(new JcrPropertyMapCacheEntry(new short[0], null));
+    }
+
+    @Test
+    public void testIntArray() throws Exception {
+        assertNotNull(new JcrPropertyMapCacheEntry(new Integer[0], null));
+        assertNotNull(new JcrPropertyMapCacheEntry(new int[0], null));
+    }
+
+    @Test
+    public void testLongArray() throws Exception {
+        assertNotNull(new JcrPropertyMapCacheEntry(new Long[0], null));
+        assertNotNull(new JcrPropertyMapCacheEntry(new long[0], null));
+    }
+
+    @Test
+    public void testFloatArray() throws Exception {
+        assertNotNull(new JcrPropertyMapCacheEntry(new Float[0], null));
+        assertNotNull(new JcrPropertyMapCacheEntry(new float[0], null));
+    }
+
+    @Test
+    public void testDoubleArray() throws Exception {
+        assertNotNull(new JcrPropertyMapCacheEntry(new Double[0], null));
+        assertNotNull(new JcrPropertyMapCacheEntry(new double[0], null));
+    }
+
+    @Test
+    public void testBooleanArray() throws Exception {
+        assertNotNull(new JcrPropertyMapCacheEntry(new Boolean[0], null));
+        assertNotNull(new JcrPropertyMapCacheEntry(new boolean[0], null));
+    }
+
+    @Test
+    public void testCharArray() throws Exception {
+        assertNotNull(new JcrPropertyMapCacheEntry(new Character[0], null));
+        assertNotNull(new JcrPropertyMapCacheEntry(new char[0], null));
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/bundles/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntryTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain