felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1815355 - in /felix/trunk/osgi-r7/configurator/src: main/java/org/apache/felix/configurator/impl/json/TypeConverter.java test/java/org/apache/felix/configurator/impl/json/TypeConverterTest.java
Date Wed, 15 Nov 2017 18:47:52 GMT
Author: cziegeler
Date: Wed Nov 15 18:47:52 2017
New Revision: 1815355

URL: http://svn.apache.org/viewvc?rev=1815355&view=rev
Log:
Fix conversion of empty array to untyped collection

Modified:
    felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/TypeConverter.java
    felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/TypeConverterTest.java

Modified: felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/TypeConverter.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/TypeConverter.java?rev=1815355&r1=1815354&r2=1815355&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/TypeConverter.java
(original)
+++ felix/trunk/osgi-r7/configurator/src/main/java/org/apache/felix/configurator/impl/json/TypeConverter.java
Wed Nov 15 18:47:52 2017
@@ -24,6 +24,7 @@ import java.io.StringWriter;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -262,7 +263,7 @@ public class TypeConverter {
                 @SuppressWarnings("unchecked")
                 final List<Object> list = (List<Object>)value;
                 if ( list.isEmpty() ) {
-                    return new String[0];
+                    return Collections.EMPTY_LIST;
                 }
                 final Object firstObject = list.get(0);
                 Object convertedValue = null;

Modified: felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/TypeConverterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/TypeConverterTest.java?rev=1815355&r1=1815354&r2=1815355&view=diff
==============================================================================
--- felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/TypeConverterTest.java
(original)
+++ felix/trunk/osgi-r7/configurator/src/test/java/org/apache/felix/configurator/impl/json/TypeConverterTest.java
Wed Nov 15 18:47:52 2017
@@ -298,6 +298,14 @@ public class TypeConverterTest {
         assertFalse(iter.hasNext());
     }
 
+    @SuppressWarnings("unchecked")
+    @Test public void testEmptyUntypedCollection() throws Exception {
+        final Object converted = getConverted("empty", "Collection");
+        assertTrue(converted instanceof Collection<?>);
+        final Iterator<Object> iter = ((Collection<Object>)converted).iterator();
+        assertFalse(iter.hasNext());
+    }
+
     @Test public void testObjectArray() throws Exception {
         final Object converted = getConverted("objects_array", null);
         assertTrue(converted.getClass().isArray());



Mime
View raw message