From 86bef9030fa4e026107db74cd9eef288beb1beca Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 22 Dec 2011 14:57:23 +0100 Subject: [PATCH 1/3] correctly handle ParseException from Formatter for String->String case (SPR-8944) --- .../beans/TypeConverterDelegate.java | 3 +++ .../validation/DataBinderTests.java | 25 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java b/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java index c2cf49eac6..b34ddbb77e 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java @@ -244,6 +244,9 @@ class TypeConverterDelegate { } if (firstAttemptEx != null) { + if (editor == null) { + throw firstAttemptEx; + } logger.debug("Original ConversionService attempt failed - ignored since " + "PropertyEditor based conversion eventually succeeded", firstAttemptEx); } diff --git a/org.springframework.context/src/test/java/org/springframework/validation/DataBinderTests.java b/org.springframework.context/src/test/java/org/springframework/validation/DataBinderTests.java index 455cb8842b..ea9fd94b11 100644 --- a/org.springframework.context/src/test/java/org/springframework/validation/DataBinderTests.java +++ b/org.springframework.context/src/test/java/org/springframework/validation/DataBinderTests.java @@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.text.ParseException; import java.util.AbstractList; import java.util.ArrayList; import java.util.Collection; @@ -51,8 +52,8 @@ import org.springframework.beans.propertyeditors.CustomNumberEditor; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.support.ResourceBundleMessageSource; import org.springframework.context.support.StaticMessageSource; -import org.springframework.core.convert.support.ConversionServiceFactory; import org.springframework.core.convert.support.DefaultConversionService; +import org.springframework.format.Formatter; import org.springframework.format.number.NumberFormatter; import org.springframework.format.support.FormattingConversionService; import org.springframework.util.StringUtils; @@ -374,6 +375,28 @@ public class DataBinderTests extends TestCase { } } + public void testBindingErrorWithStringFormatter() { + TestBean tb = new TestBean(); + DataBinder binder = new DataBinder(tb); + FormattingConversionService conversionService = new FormattingConversionService(); + DefaultConversionService.addDefaultConverters(conversionService); + conversionService.addFormatterForFieldType(String.class, new Formatter() { + public String parse(String text, Locale locale) throws ParseException { + throw new ParseException(text, 0); + } + public String print(String object, Locale locale) { + return object; + } + }); + binder.setConversionService(conversionService); + MutablePropertyValues pvs = new MutablePropertyValues(); + pvs.add("name", "test"); + + binder.bind(pvs); + assertTrue(binder.getBindingResult().hasFieldErrors("name")); + assertEquals("test", binder.getBindingResult().getFieldValue("name")); + } + public void testBindingWithFormatterAgainstList() { BeanWithIntegerList tb = new BeanWithIntegerList(); DataBinder binder = new DataBinder(tb); From 89ee5e2d80b9ec03ac832f389e5e80cabfeefb7d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 22 Dec 2011 15:06:38 +0100 Subject: [PATCH 2/3] DataBinder etc --- build-spring-framework/resources/changelog.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-spring-framework/resources/changelog.txt b/build-spring-framework/resources/changelog.txt index 526cc1fe77..a8ca5997f3 100644 --- a/build-spring-framework/resources/changelog.txt +++ b/build-spring-framework/resources/changelog.txt @@ -7,12 +7,13 @@ Changes in version 3.1.1 (2012-01-16) ------------------------------------- * context:property-placeholder's "file-encoding" attribute value is being applied correctly +* DataBinder correctly handles ParseException from Formatter for String->String case * officially deprecated TopLinkJpaDialect in favor of EclipseLink and Spring's EclipseLinkJpaDialect * fixed LocalContainerEntityManagerFactoryBean's "packagesToScan" to avoid additional provider scan * added protected "isPersistenceUnitOverrideAllowed()" method to DefaultPersistenceUnitManager +* Hibernate synchronization properly unbinds Session even in case of afterCompletion exception * Hibernate 4 LocalSessionFactoryBean implements PersistenceExceptionTranslator interface as well * Hibernate 4 LocalSessionFactoryBean does not insist on a "dataSource" reference being set -* Hibernate synchronization properly unbinds Session even in case of afterCompletion exception * added "entityInterceptor" property to Hibernate 4 LocalSessionFactoryBean * corrected fix for QuartzJobBean to work with Quartz 2.0/2.1 From 3d5e245374c997436d3802149c5ab46f4300a389 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 22 Dec 2011 15:12:55 +0100 Subject: [PATCH 3/3] CacheNamespaceHandler etc --- build-spring-framework/resources/changelog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build-spring-framework/resources/changelog.txt b/build-spring-framework/resources/changelog.txt index a8ca5997f3..73b3466171 100644 --- a/build-spring-framework/resources/changelog.txt +++ b/build-spring-framework/resources/changelog.txt @@ -6,8 +6,10 @@ http://www.springsource.org Changes in version 3.1.1 (2012-01-16) ------------------------------------- +* official support for Hibernate 4.0 GA * context:property-placeholder's "file-encoding" attribute value is being applied correctly * DataBinder correctly handles ParseException from Formatter for String->String case +* CacheNamespaceHandler actually parses cache:annotation-driven's "key-generator" attribute * officially deprecated TopLinkJpaDialect in favor of EclipseLink and Spring's EclipseLinkJpaDialect * fixed LocalContainerEntityManagerFactoryBean's "packagesToScan" to avoid additional provider scan * added protected "isPersistenceUnitOverrideAllowed()" method to DefaultPersistenceUnitManager