summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/data/util/converter/StringToCollectionConverter.java7
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/StringToCollectionConverterTest.java15
2 files changed, 22 insertions, 0 deletions
diff --git a/server/src/com/vaadin/data/util/converter/StringToCollectionConverter.java b/server/src/com/vaadin/data/util/converter/StringToCollectionConverter.java
index b86fec5558..6930b6da06 100644
--- a/server/src/com/vaadin/data/util/converter/StringToCollectionConverter.java
+++ b/server/src/com/vaadin/data/util/converter/StringToCollectionConverter.java
@@ -145,6 +145,10 @@ public class StringToCollectionConverter implements
public Collection convertToModel(String value,
Class<? extends Collection> targetType, Locale locale)
throws Converter.ConversionException {
+ if (value == null) {
+ return null;
+ }
+
int index = value.indexOf(delimiter);
int previous = 0;
Collection result = factory.createCollection(targetType);
@@ -163,6 +167,9 @@ public class StringToCollectionConverter implements
public String convertToPresentation(Collection value,
Class<? extends String> targetType, Locale locale)
throws Converter.ConversionException {
+ if (value == null) {
+ return null;
+ }
StringBuilder builder = new StringBuilder();
Converter converter = tokenConverter;
for (Iterator<?> iterator = value.iterator(); iterator.hasNext();) {
diff --git a/server/tests/src/com/vaadin/tests/data/converter/StringToCollectionConverterTest.java b/server/tests/src/com/vaadin/tests/data/converter/StringToCollectionConverterTest.java
index bcd0dc15bd..4f2dc1df81 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/StringToCollectionConverterTest.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/StringToCollectionConverterTest.java
@@ -22,6 +22,7 @@ import java.util.EnumSet;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import java.util.Set;
import java.util.Vector;
@@ -151,6 +152,20 @@ public class StringToCollectionConverterTest {
iterator.hasNext());
}
+ @Test
+ public void convertToModel_null() {
+ StringToCollectionConverter converter = new StringToCollectionConverter();
+ Assert.assertNull(converter.convertToModel(null, ArrayList.class,
+ Locale.ENGLISH));
+ }
+
+ @Test
+ public void convertToPresentation_null() {
+ StringToCollectionConverter converter = new StringToCollectionConverter();
+ Assert.assertNull(converter.convertToPresentation(null, String.class,
+ Locale.ENGLISH));
+ }
+
public enum TestEnum {
X, Y, Z;
}