Skip to content

SPR-9498: relax logic detecting successful property editor after conversion exception #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 4, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.DS_Store
.settings
.springBeans
target
bin
build.sh
integration-repo
Expand All @@ -17,6 +18,7 @@ build
.classpath
.project
argfile*
pom.xml

# IDEA metadata and output dirs
*.iml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
*
* @author Juergen Hoeller
* @author Rob Harrop
* @author Dave Syer
* @since 2.0
* @see BeanWrapperImpl
* @see SimpleTypeConverter
Expand Down Expand Up @@ -244,7 +245,7 @@ else if (convertedValue instanceof String && !requiredType.isInstance(convertedV
}

if (firstAttemptEx != null) {
if (editor == null && convertedValue == newValue) {
if (editor == null && convertedValue == newValue && requiredType!=null && !ClassUtils.isAssignableValue(requiredType, convertedValue)) {
throw firstAttemptEx;
}
logger.debug("Original ConversionService attempt failed - ignored since " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@
import java.util.TreeSet;

import org.apache.commons.logging.LogFactory;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.beans.propertyeditors.StringArrayPropertyEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.beans.support.DerivedFromProtectedBaseBean;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;

Expand All @@ -66,9 +68,34 @@
* @author Alef Arendsen
* @author Arjen Poutsma
* @author Chris Beams
* @author Dave Syer
*/
public final class BeanWrapperTests {

@Test
public void testNullNestedTypeDescriptorWithNoConversionService() {
Foo foo = new Foo();
BeanWrapperImpl wrapper = new BeanWrapperImpl(foo);
wrapper.setAutoGrowNestedPaths(true);
wrapper.setPropertyValue("listOfMaps[0]['luckyNumber']", "9");
assertEquals("9", foo.listOfMaps.get(0).get("luckyNumber"));
}

@Test
public void testNullNestedTypeDescriptorWithBadConversionService() {
Foo foo = new Foo();
BeanWrapperImpl wrapper = new BeanWrapperImpl(foo);
wrapper.setConversionService(new GenericConversionService() {
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
throw new ConversionFailedException(sourceType, targetType, source, null);
}
});
wrapper.setAutoGrowNestedPaths(true);
wrapper.setPropertyValue("listOfMaps[0]['luckyNumber']", "9");
assertEquals("9", foo.listOfMaps.get(0).get("luckyNumber"));
}

@Test
public void testNullNestedTypeDescriptor() {
Foo foo = new Foo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.util.concurrent.CopyOnWriteArraySet;

import org.springframework.util.LinkedCaseInsensitiveMap;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
* Factory for collections, being aware of Java 5 and Java 6 collections.
Expand Down Expand Up @@ -305,6 +307,9 @@ public static Map createMap(Class<?> mapType, int initialCapacity) {
else if (SortedMap.class.equals(mapType) || mapType.equals(navigableMapClass)) {
return new TreeMap();
}
else if (MultiValueMap.class.equals(mapType)) {
return new LinkedMultiValueMap();
}
else {
throw new IllegalArgumentException("Unsupported Map interface: " + mapType.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

import junit.framework.TestCase;

import org.springframework.util.MultiValueMap;

/**
* @author Darren Davison
* @author Juergen Hoeller
* @author Dave Syer
*/
public class CollectionFactoryTests extends TestCase {

Expand All @@ -50,6 +53,11 @@ public void testConcurrentMap() {
assertTrue(map.getClass().getName().endsWith("ConcurrentHashMap"));
}

public void testMultiValueMap() {
Map map = CollectionFactory.createMap(MultiValueMap.class, 16);
assertTrue(map.getClass().getName().endsWith("MultiValueMap"));
}

public void testConcurrentMapWithExplicitInterface() {
ConcurrentMap map = CollectionFactory.createConcurrentMap(16);
assertTrue(map.getClass().getSuperclass().getName().endsWith("ConcurrentHashMap"));
Expand Down