Browse Source

SelectedValueComparator defensively handles null values in exhaustiveCompare

Issue: SPR-12001
(cherry picked from commit 980f971)
pull/689/head
Juergen Hoeller 12 years ago
parent
commit
a3ebf13579
  1. 16
      spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java

16
spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -94,10 +94,10 @@ abstract class SelectedValueComparator { @@ -94,10 +94,10 @@ abstract class SelectedValueComparator {
selected = collectionCompare(CollectionUtils.arrayToList(boundValue), candidateValue, bindStatus);
}
else if (boundValue instanceof Collection) {
selected = collectionCompare((Collection) boundValue, candidateValue, bindStatus);
selected = collectionCompare((Collection<?>) boundValue, candidateValue, bindStatus);
}
else if (boundValue instanceof Map) {
selected = mapCompare((Map) boundValue, candidateValue, bindStatus);
selected = mapCompare((Map<?, ?>) boundValue, candidateValue, bindStatus);
}
if (!selected) {
selected = exhaustiveCompare(boundValue, candidateValue, bindStatus.getEditor(), null);
@ -105,7 +105,7 @@ abstract class SelectedValueComparator { @@ -105,7 +105,7 @@ abstract class SelectedValueComparator {
return selected;
}
private static boolean collectionCompare(Collection boundCollection, Object candidateValue, BindStatus bindStatus) {
private static boolean collectionCompare(Collection<?> boundCollection, Object candidateValue, BindStatus bindStatus) {
try {
if (boundCollection.contains(candidateValue)) {
return true;
@ -117,7 +117,7 @@ abstract class SelectedValueComparator { @@ -117,7 +117,7 @@ abstract class SelectedValueComparator {
return exhaustiveCollectionCompare(boundCollection, candidateValue, bindStatus);
}
private static boolean mapCompare(Map boundMap, Object candidateValue, BindStatus bindStatus) {
private static boolean mapCompare(Map<?, ?> boundMap, Object candidateValue, BindStatus bindStatus) {
try {
if (boundMap.containsKey(candidateValue)) {
return true;
@ -130,7 +130,7 @@ abstract class SelectedValueComparator { @@ -130,7 +130,7 @@ abstract class SelectedValueComparator {
}
private static boolean exhaustiveCollectionCompare(
Collection collection, Object candidateValue, BindStatus bindStatus) {
Collection<?> collection, Object candidateValue, BindStatus bindStatus) {
Map<PropertyEditor, Object> convertedValueCache = new HashMap<PropertyEditor, Object>(1);
PropertyEditor editor = null;
@ -164,8 +164,8 @@ abstract class SelectedValueComparator { @@ -164,8 +164,8 @@ abstract class SelectedValueComparator {
return true;
}
}
else if (boundValue.getClass().isEnum()) {
Enum boundEnum = (Enum) boundValue;
else if (boundValue != null && boundValue.getClass().isEnum()) {
Enum<?> boundEnum = (Enum<?>) boundValue;
String enumCodeAsString = ObjectUtils.getDisplayString(boundEnum.name());
if (enumCodeAsString.equals(candidateDisplayString)) {
return true;

Loading…
Cancel
Save