You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by da...@apache.org on 2017/11/14 04:30:07 UTC

svn commit: r1815185 - in /felix/trunk/converter/converter/src: main/java/org/apache/felix/converter/impl/ConvertingImpl.java test/java/org/apache/felix/converter/impl/ConverterTest.java

Author: davidb
Date: Tue Nov 14 04:30:07 2017
New Revision: 1815185

URL: http://svn.apache.org/viewvc?rev=1815185&view=rev
Log:
Support null default values for Converter

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=1815185&r1=1815184&r2=1815185&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 04:30:07 2017
@@ -155,7 +155,7 @@ class ConvertingImpl extends AbstractSpe
         if (res2 != null) {
             return res2;
         } else {
-            if (defaultValue != null)
+            if (hasDefault)
                 return converter.convert(defaultValue).sourceAs(sourceAsClass).targetAs(targetAsClass).to(targetClass);
             else
                 throw new ConversionException("Cannot convert " + object + " to " + targetAsClass);

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=1815185&r1=1815184&r2=1815185&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 04:30:07 2017
@@ -348,6 +348,7 @@ public class ConverterTest {
     public void testExceptionDefaultValue() {
         assertEquals(42, (int) converter.convert("haha").defaultValue(42).to(int.class));
         assertEquals(999, (int) converter.convert("haha").defaultValue(999).to(int.class));
+        assertNull(converter.convert("haha").defaultValue(null).to(int.class));
         try {
             converter.convert("haha").to(int.class);
             fail("Should have thrown an exception");