From a3ebf135798bc9c27c3fb757d962666db4618862 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 24 Jul 2014 17:46:04 +0200 Subject: [PATCH] SelectedValueComparator defensively handles null values in exhaustiveCompare Issue: SPR-12001 (cherry picked from commit 980f971) --- .../tags/form/SelectedValueComparator.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java index 8446f9f2b14..9fcfcf509a0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java @@ -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 { 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 { 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 { 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 { } private static boolean exhaustiveCollectionCompare( - Collection collection, Object candidateValue, BindStatus bindStatus) { + Collection collection, Object candidateValue, BindStatus bindStatus) { Map convertedValueCache = new HashMap(1); PropertyEditor editor = null; @@ -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;