felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1815223 - in /felix/trunk/converter/converter/src: main/java/org/apache/felix/converter/impl/ConvertingImpl.java test/java/org/apache/felix/converter/impl/ConverterTest.java
Date Tue, 14 Nov 2017 15:02:47 GMT
Author: davidb
Date: Tue Nov 14 15:02:47 2017
New Revision: 1815223

URL: http://svn.apache.org/viewvc?rev=1815223&view=rev
Log:
Fix Converter default handling for collections

Modified:
    felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
    felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java

Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java?rev=1815223&r1=1815222&r2=1815223&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
(original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
Tue Nov 14 15:02:47 2017
@@ -240,16 +240,16 @@ class ConvertingImpl extends AbstractSpe
 
         for (Object o : cv) {
             if (targetElementType != null) {
-                InternalConverting converting = converter.convert(o);
-                if (hasDefault) {
-                    // TODO this needs to be done more generally
-                    converting.defaultValue(defaultValue);
+                try {
+                    o = converter.convert(o).to(targetElementType);
+                } catch (ConversionException ce) {
+                    if (hasDefault) {
+                        return (T) defaultValue;
+                    }
                 }
-                o = converting.to(targetElementType);
             }
 
-            if (!(o == null && cv.size() == 1))
-                instance.add(o);
+            instance.add(o);
         }
 
         return (T) instance;

Modified: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java?rev=1815223&r1=1815222&r2=1815223&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
(original)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
Tue Nov 14 15:02:47 2017
@@ -539,7 +539,7 @@ public class ConverterTest {
         long l = converter.convert(null).defaultValue("12").to(Long.class);
         assertEquals(12L, l);
         assertNull(converter.convert("haha").defaultValue(null).to(Integer.class));
-        assertEquals(0, converter.convert("test").defaultValue(null).to(new TypeReference<List<Long>>()
{}).size());
+        assertNull(converter.convert("test").defaultValue(null).to(new TypeReference<List<Long>>()
{}));
     }
 
     @Test



Mime
View raw message