fixed TypeDescriptor toString for MethodParameter annotations (SPR-6924)

This commit is contained in:
Juergen Hoeller 2010-03-04 13:50:43 +00:00
parent 9ede9fe697
commit 0444ab236a
3 changed files with 27 additions and 9 deletions

View File

@ -249,7 +249,6 @@ public class ApplicationContextExpressionTests {
GenericApplicationContext ac = new GenericApplicationContext(); GenericApplicationContext ac = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ac); AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
GenericBeanDefinition bd = new GenericBeanDefinition(); GenericBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(TestBean.class); bd.setBeanClass(TestBean.class);
bd.getPropertyValues().add("country", "#{systemProperties.country}"); bd.getPropertyValues().add("country", "#{systemProperties.country}");
@ -264,12 +263,10 @@ public class ApplicationContextExpressionTests {
public void checkPropertiesAccess() { public void checkPropertiesAccess() {
throw new AccessControlException("Not Allowed"); throw new AccessControlException("Not Allowed");
} }
@Override @Override
public void checkPermission(Permission perm) { public void checkPermission(Permission perm) {
// allow everything else // allow everything else
} }
}; };
System.setSecurityManager(securityManager); System.setSecurityManager(securityManager);
ac.refresh(); ac.refresh();
@ -284,6 +281,22 @@ public class ApplicationContextExpressionTests {
} }
} }
@Test
public void stringConcatenationWithDebugLogging() {
GenericApplicationContext ac = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
GenericBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(String.class);
bd.getConstructorArgumentValues().addGenericArgumentValue("test-#{ T(java.lang.System).currentTimeMillis() }");
ac.registerBeanDefinition("str", bd);
ac.refresh();
String str = ac.getBean("str", String.class);
assertTrue(str.startsWith("test-"));
}
public static class ValueTestBean implements Serializable { public static class ValueTestBean implements Serializable {
@Autowired @Value("XXX#{tb0.name}YYY#{mySpecialAttr}ZZZ") @Autowired @Value("XXX#{tb0.name}YYY#{mySpecialAttr}ZZZ")

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2010 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -230,7 +230,12 @@ public class MethodParameter {
if (this.parameterAnnotations == null) { if (this.parameterAnnotations == null) {
Annotation[][] annotationArray = (this.method != null ? Annotation[][] annotationArray = (this.method != null ?
this.method.getParameterAnnotations() : this.constructor.getParameterAnnotations()); this.method.getParameterAnnotations() : this.constructor.getParameterAnnotations());
this.parameterAnnotations = annotationArray[this.parameterIndex]; if (this.parameterIndex >= 0 && this.parameterIndex < annotationArray.length) {
this.parameterAnnotations = annotationArray[this.parameterIndex];
}
else {
this.parameterAnnotations = new Annotation[0];
}
} }
return this.parameterAnnotations; return this.parameterAnnotations;
} }

View File

@ -28,6 +28,7 @@ import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.core.GenericTypeResolver; import org.springframework.core.GenericTypeResolver;
import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
@ -38,7 +39,6 @@ import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory; import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.core.convert.converter.ConverterRegistry; import org.springframework.core.convert.converter.ConverterRegistry;
import org.springframework.core.convert.converter.GenericConverter; import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.core.style.StylerUtils;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
@ -122,7 +122,7 @@ public class GenericConversionService implements ConversionService, ConverterReg
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
assertNotNull(sourceType, targetType); assertNotNull(sourceType, targetType);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Converting value " + StylerUtils.style(source) +" of " + sourceType + " to " + targetType); logger.debug("Converting value of " + sourceType + " to " + targetType);
} }
if (sourceType == TypeDescriptor.NULL) { if (sourceType == TypeDescriptor.NULL) {
Assert.isTrue(source == null, "The source must be null if sourceType == TypeDescriptor.NULL"); Assert.isTrue(source == null, "The source must be null if sourceType == TypeDescriptor.NULL");
@ -246,8 +246,8 @@ public class GenericConversionService implements ConversionService, ConverterReg
} }
private GenericConverter findConverterForClassPair(TypeDescriptor sourceType, TypeDescriptor targetType) { private GenericConverter findConverterForClassPair(TypeDescriptor sourceType, TypeDescriptor targetType) {
if (logger.isDebugEnabled()) { if (logger.isTraceEnabled()) {
logger.debug("Looking for Converter to convert from " + sourceType + " to " + targetType); logger.trace("Looking for Converter to convert from " + sourceType + " to " + targetType);
} }
Class<?> sourceObjectType = sourceType.getObjectType(); Class<?> sourceObjectType = sourceType.getObjectType();
if (sourceObjectType.isInterface()) { if (sourceObjectType.isInterface()) {