sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1712652 - in /sling/trunk/testing/mocks/jcr-mock/src: main/java/org/apache/sling/testing/mock/jcr/MockProperty.java test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
Date Wed, 04 Nov 2015 21:10:21 GMT
Author: sseifert
Date: Wed Nov  4 21:10:21 2015
New Revision: 1712652

URL: http://svn.apache.org/viewvc?rev=1712652&view=rev
Log:
SLING-5257 MockProperty getType generates java.lang.ArrayIndexOutOfBoundsException when the
underlying array value is empty

Modified:
    sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
    sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java

Modified: sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java?rev=1712652&r1=1712651&r2=1712652&view=diff
==============================================================================
--- sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
(original)
+++ sling/trunk/testing/mocks/jcr-mock/src/main/java/org/apache/sling/testing/mock/jcr/MockProperty.java
Wed Nov  4 21:10:21 2015
@@ -25,6 +25,7 @@ import java.util.Calendar;
 import javax.jcr.Binary;
 import javax.jcr.Node;
 import javax.jcr.Property;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
@@ -197,7 +198,12 @@ class MockProperty extends AbstractItem
 
     @Override
     public int getType() throws RepositoryException {
-        return this.itemData.getValues()[0].getType();
+        if (this.itemData.getValues().length > 0) {
+            return this.itemData.getValues()[0].getType();
+        }
+        else {
+            return PropertyType.UNDEFINED;
+        }    
     }
 
     @Override

Modified: sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java?rev=1712652&r1=1712651&r2=1712652&view=diff
==============================================================================
--- sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
(original)
+++ sling/trunk/testing/mocks/jcr-mock/src/test/java/org/apache/sling/testing/mock/jcr/MockPropertyTest.java
Wed Nov  4 21:10:21 2015
@@ -30,6 +30,7 @@ import java.util.Calendar;
 
 import javax.jcr.Node;
 import javax.jcr.Property;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
@@ -237,4 +238,12 @@ public class MockPropertyTest {
         assertArrayEquals(new long[] { 2 }, prop1.getLengths());
     }
 
+    @Test
+    public void testEmptyArrayGetType() throws RepositoryException {
+        this.node1.setProperty("prop1", new Value[] {});
+        Property prop1 = this.node1.getProperty("prop1");
+        assertTrue(prop1.isMultiple());
+        assertEquals(PropertyType.UNDEFINED, prop1.getType());
+    }
+    
 }



Mime
View raw message