diff options
author | Artur Signell <artur@vaadin.com> | 2013-11-15 18:40:57 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-12-03 13:27:31 +0000 |
commit | 25fc48c52067237faa208cea849a775a7aa1668c (patch) | |
tree | 39acbb1764fc64170fff033cdad9f51be18793e0 | |
parent | 54a5667b2cebf6df7825d92c287112f6be64fe7d (diff) | |
download | vaadin-framework-25fc48c52067237faa208cea849a775a7aa1668c.tar.gz vaadin-framework-25fc48c52067237faa208cea849a775a7aa1668c.zip |
Do not throw NPE if conversion messages is null (#12962)
Change-Id: Ie2b95ed4da89e2c5ab8b462300a6f4bd28dc7570
-rw-r--r-- | server/src/com/vaadin/ui/AbstractField.java | 17 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java | 15 |
2 files changed, 24 insertions, 8 deletions
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java index 6a52d6b849..b96e331889 100644 --- a/server/src/com/vaadin/ui/AbstractField.java +++ b/server/src/com/vaadin/ui/AbstractField.java @@ -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; } diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java index ad762f8931..887f1b8ff3 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java @@ -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()); |