diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2013-08-01 11:53:34 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-08-01 10:33:37 +0000 |
commit | 7fc105440755357d469d87b9523afc6f84e0bda7 (patch) | |
tree | ec11f2008f6ac2d75605f3353c5ebb6fc305e157 /server/src/com | |
parent | 326bbb5e91564a39553b13f5a3a00b7ff5dd40ec (diff) | |
download | vaadin-framework-7fc105440755357d469d87b9523afc6f84e0bda7.tar.gz vaadin-framework-7fc105440755357d469d87b9523afc6f84e0bda7.zip |
Ensure StringToIntegerConverter rejects values outside range of int (#12230)
Change-Id: I150bee64144045355bfa75ac10ede663d3feb5ce
Diffstat (limited to 'server/src/com')
-rw-r--r-- | server/src/com/vaadin/data/util/converter/StringToIntegerConverter.java | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/server/src/com/vaadin/data/util/converter/StringToIntegerConverter.java b/server/src/com/vaadin/data/util/converter/StringToIntegerConverter.java index bc436112fe..f6f668ad4d 100644 --- a/server/src/com/vaadin/data/util/converter/StringToIntegerConverter.java +++ b/server/src/com/vaadin/data/util/converter/StringToIntegerConverter.java @@ -62,7 +62,22 @@ public class StringToIntegerConverter extends Class<? extends Integer> targetType, Locale locale) throws ConversionException { Number n = convertToNumber(value, targetType, locale); - return n == null ? null : n.intValue(); + + if (n == null) { + return null; + } + + int intValue = n.intValue(); + if (intValue == n.longValue()) { + // If the value of n is outside the range of long, the return value + // of longValue() is either Long.MIN_VALUE or Long.MAX_VALUE. The + // above comparison promotes int to long and thus does not need to + // consider wrap-around. + return intValue; + } + + throw new ConversionException("Could not convert '" + value + "' to " + + Integer.class.getName() + ": value out of range"); } |