You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2016/12/21 14:12:45 UTC
svn commit: r1775427 - in /sling/trunk/bundles/api/src:
main/java/org/apache/sling/api/wrappers/
main/java/org/apache/sling/api/wrappers/impl/
test/java/org/apache/sling/api/wrappers/
test/java/org/apache/sling/api/wrappers/impl/
Author: sseifert
Date: Wed Dec 21 14:12:45 2016
New Revision: 1775427
URL: http://svn.apache.org/viewvc?rev=1775427&view=rev
Log:
SLING-6424 ValueMapDecorator: Empty arrays for multi-value properties should not be converted to null
also increase third digit of package version because the contract of the ValueMap impl changed (from wrong to correct behavior)
Modified:
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/impl/ObjectConverter.java
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/package-info.java
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/ValueMapDecoratorTest.java
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/Convert.java
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/ObjectConverterTest.java
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/impl/ObjectConverter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/impl/ObjectConverter.java?rev=1775427&r1=1775426&r2=1775427&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/impl/ObjectConverter.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/impl/ObjectConverter.java Wed Dec 21 14:12:45 2016
@@ -48,9 +48,6 @@ public final class ObjectConverter {
// check if direct assignment is possible
if (type.isAssignableFrom(obj.getClass())) {
- if (obj.getClass().isArray() && Array.getLength(obj) == 0) {
- return null;
- }
return (T)obj;
}
@@ -169,18 +166,15 @@ public final class ObjectConverter {
resultList.add(singleValueResult);
}
}
- if (resultList.isEmpty()) {
- return null;
- }
- return resultList.toArray((T[]) Array.newInstance(type, resultList.size()));
+ return resultList.toArray((T[])Array.newInstance(type, resultList.size()));
}
else {
final T singleValueResult = convert(obj, type);
// return null for type conversion errors instead of single element array with value null
if (singleValueResult == null) {
- return null;
+ return (T[])Array.newInstance(type, 0);
}
- final T[] arrayResult = (T[]) Array.newInstance(type, 1);
+ final T[] arrayResult = (T[])Array.newInstance(type, 1);
arrayResult[0] = singleValueResult;
return arrayResult;
}
Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/package-info.java?rev=1775427&r1=1775426&r2=1775427&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/package-info.java (original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/wrappers/package-info.java Wed Dec 21 14:12:45 2016
@@ -17,8 +17,7 @@
* under the License.
*/
-@Version("2.6.0")
+@Version("2.6.1")
package org.apache.sling.api.wrappers;
import org.osgi.annotation.versioning.Version;
-
Modified: sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/ValueMapDecoratorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/ValueMapDecoratorTest.java?rev=1775427&r1=1775426&r2=1775427&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/ValueMapDecoratorTest.java (original)
+++ sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/ValueMapDecoratorTest.java Wed Dec 21 14:12:45 2016
@@ -47,8 +47,8 @@ public class ValueMapDecoratorTest {
public void testIncompatibleTypeInArray() {
map.put("prop1", new String[] { "test", "test2" });
map.put("prop2", "test");
- Assert.assertNull("Not convertible type should return null", valueMap.get("prop1", Integer[].class));
- Assert.assertNull("Not convertible type should return null", valueMap.get("prop2", Integer[].class));
+ Assert.assertArrayEquals("Not convertible type should return empty array", new Integer[0], valueMap.get("prop1", Integer[].class));
+ Assert.assertArrayEquals("Not convertible type should return empt array", new Integer[0], valueMap.get("prop2", Integer[].class));
}
// SLING-662
@@ -94,8 +94,12 @@ public class ValueMapDecoratorTest {
public void testPrimitiveTypes() {
map.put("prop1", new String[] { "1", "2" });
Assert.assertNull("ValueMap should not support conversion to primitive type", valueMap.get("prop1", int.class));
- Assert.assertNull("ValueMap should not support conversion to array of primitive type",
- valueMap.get("prop1", int[].class));
+ }
+ @Test(expected=ClassCastException.class)
+ public void testPrimitiveTypesArray() {
+ map.put("prop1", new String[] { "1", "2" });
+ Assert.assertArrayEquals("ValueMap should not support conversion to array of primitive type",
+ new int[0], valueMap.get("prop1", int[].class));
}
@Test
Modified: sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/Convert.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/Convert.java?rev=1775427&r1=1775426&r2=1775427&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/Convert.java (original)
+++ sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/Convert.java Wed Dec 21 14:12:45 2016
@@ -137,28 +137,30 @@ final class Convert {
assertConversion(expected1, input1, expectedType);
// single value to array
+ Object expectedSingletonArray;
if (expected1 == null && expected2 == null) {
- assertConversion(nullValue, input1, expectedArrayType);
+ expectedSingletonArray = Array.newInstance(expectedType, 0);
}
else {
- Object expectedSingletonArray = Array.newInstance(expectedType, 1);
+ expectedSingletonArray = Array.newInstance(expectedType, 1);
Array.set(expectedSingletonArray, 0, expected1);
- assertConversion(expectedSingletonArray, input1, expectedArrayType);
}
+ assertConversion(expectedSingletonArray, input1, expectedArrayType);
// array to array
Object inputDoubleArray = Array.newInstance(inputType, 2);
Array.set(inputDoubleArray, 0, input1);
Array.set(inputDoubleArray, 1, input2);
+ Object expectedDoubleArray;
if (expected1 == null && expected2 == null) {
- assertConversion(null, inputDoubleArray, expectedArrayType);
+ expectedDoubleArray = Array.newInstance(expectedType, 0);
}
else {
- Object expectedDoubleArray = Array.newInstance(expectedType, 2);
+ expectedDoubleArray = Array.newInstance(expectedType, 2);
Array.set(expectedDoubleArray, 0, expected1);
Array.set(expectedDoubleArray, 1, expected2);
- assertConversion(expectedDoubleArray, inputDoubleArray, expectedArrayType);
}
+ assertConversion(expectedDoubleArray, inputDoubleArray, expectedArrayType);
// array to single (first) value
assertConversion(expected1, inputDoubleArray, expectedType);
@@ -174,7 +176,8 @@ final class Convert {
assertConversion(nullValue, inputEmptyArray, expectedType);
// empty array to array
- assertConversion(null, inputEmptyArray, expectedArrayType);
+ Object expectedEmptyArray = Array.newInstance(expectedType, 0);
+ assertConversion(expectedEmptyArray, inputEmptyArray, expectedArrayType);
}
@SuppressWarnings("unchecked")
Modified: sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/ObjectConverterTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/ObjectConverterTest.java?rev=1775427&r1=1775426&r2=1775427&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/ObjectConverterTest.java (original)
+++ sling/trunk/bundles/api/src/test/java/org/apache/sling/api/wrappers/impl/ObjectConverterTest.java Wed Dec 21 14:12:45 2016
@@ -223,7 +223,7 @@ public class ObjectConverterTest {
public void testPrimitiveByteArray() {
byte[] array = new byte[] { 0x01, 0x02, 0x03 };
assertArrayEquals(array, ObjectConverter.convert(array, byte[].class));
- assertNull(ObjectConverter.convert(new byte[0], byte[].class));
+ assertArrayEquals(new byte[0], ObjectConverter.convert(new byte[0], byte[].class));
assertNull(ObjectConverter.convert(null, byte[].class));
}