ServletRequestAttributes considers standard Number subclasses (as defined in NumberUtils) as immutable

Issue: SPR-11738
This commit is contained in:
Juergen Hoeller
2014-05-27 17:43:31 +02:00
parent bb6e07bd3a
commit 8f2ed66b4a
2 changed files with 36 additions and 3 deletions

View File

@@ -21,6 +21,9 @@ import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* Miscellaneous utility methods for number conversion and parsing.
@@ -37,6 +40,25 @@ public abstract class NumberUtils {
private static final BigInteger LONG_MAX = BigInteger.valueOf(Long.MAX_VALUE);
/**
* Standard number types (all immutable):
* Byte, Short, Integer, Long, BigInteger, Float, Double, BigDecimal.
*/
public static final Set<Class<?>> STANDARD_NUMBER_TYPES;
static {
Set<Class<?>> numberTypes = new HashSet<Class<?>>(8);
numberTypes.add(Byte.class);
numberTypes.add(Short.class);
numberTypes.add(Integer.class);
numberTypes.add(Long.class);
numberTypes.add(BigInteger.class);
numberTypes.add(Float.class);
numberTypes.add(Double.class);
numberTypes.add(BigDecimal.class);
STANDARD_NUMBER_TYPES = Collections.unmodifiableSet(numberTypes);
}
/**
* Convert the given number into an instance of the given target class.