summaryrefslogtreecommitdiffstats
path: root/server/src/com
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-12-09 22:16:50 +0200
committerHenri Sara <hesara@vaadin.com>2014-12-11 07:20:28 +0000
commitc4e4f449464f22c11e33b92f8aa578db959e92b2 (patch)
treeb673bea7db35b3a55a13d4cb07e4012ee68c8f8c /server/src/com
parentb91063f884108bfc69a617846d91263339b062fe (diff)
downloadvaadin-framework-c4e4f449464f22c11e33b92f8aa578db959e92b2.tar.gz
vaadin-framework-c4e4f449464f22c11e33b92f8aa578db959e92b2.zip
Convert empty string to null Enum value, only throw ConversionExceptions (#14756)
Change-Id: I027a245975db12e3661740bd233edd98e73994e9
Diffstat (limited to 'server/src/com')
-rw-r--r--server/src/com/vaadin/data/util/converter/StringToEnumConverter.java20
1 files changed, 11 insertions, 9 deletions
diff --git a/server/src/com/vaadin/data/util/converter/StringToEnumConverter.java b/server/src/com/vaadin/data/util/converter/StringToEnumConverter.java
index a1328d831c..29bf8fc400 100644
--- a/server/src/com/vaadin/data/util/converter/StringToEnumConverter.java
+++ b/server/src/com/vaadin/data/util/converter/StringToEnumConverter.java
@@ -34,7 +34,7 @@ public class StringToEnumConverter implements Converter<String, Enum> {
@Override
public Enum convertToModel(String value, Class<? extends Enum> targetType,
Locale locale) throws ConversionException {
- if (value == null) {
+ if (value == null || value.trim().equals("")) {
return null;
}
if (locale == null) {
@@ -46,19 +46,21 @@ public class StringToEnumConverter implements Converter<String, Enum> {
String result = value.replace(" ", "_").toUpperCase(locale);
try {
return Enum.valueOf(targetType, result);
- } catch (IllegalArgumentException ee) {
+ } catch (Exception ee) {
// There was no match. Try to compare the available values to see if
// the constant is using something else than all upper case
-
- EnumSet<?> set = EnumSet.allOf(targetType);
- for (Enum e : set) {
- if (e.name().toUpperCase(locale).equals(result)) {
- return e;
+ try {
+ EnumSet<?> set = EnumSet.allOf(targetType);
+ for (Enum e : set) {
+ if (e.name().toUpperCase(locale).equals(result)) {
+ return e;
+ }
}
+ } catch (Exception e) {
}
- // Fallback did not work either, re-throw original exception so user
- // knows what went wrong
+ // Fallback did not work either, re-throw original exception so
+ // user knows what went wrong
throw new ConversionException(ee);
}
}