]> source.dussan.org Git - vaadin-framework.git/commitdiff
Do not throw NPE if conversion messages is null (#12962)
authorArtur Signell <artur@vaadin.com>
Fri, 15 Nov 2013 16:40:57 +0000 (18:40 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 3 Dec 2013 13:27:31 +0000 (13:27 +0000)
Change-Id: Ie2b95ed4da89e2c5ab8b462300a6f4bd28dc7570

server/src/com/vaadin/ui/AbstractField.java
server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java

index 6a52d6b849e47b3c5dfe9165f037b5e8ad448506..b96e331889713069c2e6f97e66f25db3199740ef 100644 (file)
@@ -783,15 +783,16 @@ public abstract class AbstractField<T> extends AbstractComponent implements
             ConversionException e) {
         String conversionError = getConversionError();
 
-        if (dataSourceType != null) {
-            conversionError = conversionError.replace("{0}",
-                    dataSourceType.getSimpleName());
-        }
-        if (e != null) {
-            conversionError = conversionError.replace("{1}",
-                    e.getLocalizedMessage());
+        if (conversionError != null) {
+            if (dataSourceType != null) {
+                conversionError = conversionError.replace("{0}",
+                        dataSourceType.getSimpleName());
+            }
+            if (e != null) {
+                conversionError = conversionError.replace("{1}",
+                        e.getLocalizedMessage());
+            }
         }
-
         return conversionError;
     }
 
index ad762f8931c0e358a649d681b9c6a0de3e2bb3c5..887f1b8ff3aef05f5f2aa7812c6445a1da79f006 100644 (file)
@@ -54,6 +54,21 @@ public class AbsFieldValueConversionError extends TestCase {
 
     }
 
+    public void testNullConversionMessages() {
+        TextField tf = new TextField();
+        tf.setConverter(new StringToIntegerConverter());
+        tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age"));
+        tf.setConversionError(null);
+        tf.setValue("abc");
+        try {
+            tf.validate();
+            fail();
+        } catch (InvalidValueException e) {
+            Assert.assertEquals(null, e.getMessage());
+        }
+
+    }
+
     public void testDefaultConversionErrorMessage() {
         TextField tf = new TextField();
         tf.setConverter(new StringToIntegerConverter());