Skip to content

Commit e819999

Browse files
committed
Polishing
1 parent 3a1f7b6 commit e819999

File tree

15 files changed

+172
-147
lines changed

15 files changed

+172
-147
lines changed

spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,22 +46,25 @@ class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
4646

4747
private final Method writeMethod;
4848

49-
private final Class<?> propertyEditorClass;
50-
5149
private volatile Set<Method> ambiguousWriteMethods;
5250

51+
private MethodParameter writeMethodParameter;
52+
5353
private Class<?> propertyType;
5454

55-
private MethodParameter writeMethodParameter;
55+
private final Class<?> propertyEditorClass;
5656

5757

5858
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
5959
Method readMethod, Method writeMethod, Class<?> propertyEditorClass)
6060
throws IntrospectionException {
6161

6262
super(propertyName, null, null);
63+
64+
if (beanClass == null) {
65+
throw new IntrospectionException("Bean class must not be null");
66+
}
6367
this.beanClass = beanClass;
64-
this.propertyEditorClass = propertyEditorClass;
6568

6669
Method readMethodToUse = BridgeMethodResolver.findBridgedMethod(readMethod);
6770
Method writeMethodToUse = BridgeMethodResolver.findBridgedMethod(writeMethod);
@@ -93,8 +96,11 @@ public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyNam
9396
this.ambiguousWriteMethods = ambiguousCandidates;
9497
}
9598
}
99+
100+
this.propertyEditorClass = propertyEditorClass;
96101
}
97102

103+
98104
public Class<?> getBeanClass() {
99105
return this.beanClass;
100106
}
@@ -120,9 +126,15 @@ public Method getWriteMethodForActualAccess() {
120126
return this.writeMethod;
121127
}
122128

123-
@Override
124-
public Class<?> getPropertyEditorClass() {
125-
return this.propertyEditorClass;
129+
public synchronized MethodParameter getWriteMethodParameter() {
130+
if (this.writeMethod == null) {
131+
return null;
132+
}
133+
if (this.writeMethodParameter == null) {
134+
this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
135+
GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
136+
}
137+
return this.writeMethodParameter;
126138
}
127139

128140
@Override
@@ -144,15 +156,9 @@ public synchronized Class<?> getPropertyType() {
144156
return this.propertyType;
145157
}
146158

147-
public synchronized MethodParameter getWriteMethodParameter() {
148-
if (this.writeMethod == null) {
149-
return null;
150-
}
151-
if (this.writeMethodParameter == null) {
152-
this.writeMethodParameter = new MethodParameter(this.writeMethod, 0);
153-
GenericTypeResolver.resolveParameterType(this.writeMethodParameter, this.beanClass);
154-
}
155-
return this.writeMethodParameter;
159+
@Override
160+
public Class<?> getPropertyEditorClass() {
161+
return this.propertyEditorClass;
156162
}
157163

158164
}

spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
238238
if (requiredConstructor != null) {
239239
throw new BeanCreationException(beanName,
240240
"Invalid autowire-marked constructor: " + candidate +
241-
". Found another constructor with 'required' Autowired annotation: " +
241+
". Found constructor with 'required' Autowired annotation already: " +
242242
requiredConstructor);
243243
}
244244
if (candidate.getParameterTypes().length == 0) {
@@ -250,7 +250,7 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
250250
if (!candidates.isEmpty()) {
251251
throw new BeanCreationException(beanName,
252252
"Invalid autowire-marked constructors: " + candidates +
253-
". Found another constructor with 'required' Autowired annotation: " +
253+
". Found constructor with 'required' Autowired annotation: " +
254254
candidate);
255255
}
256256
requiredConstructor = candidate;
@@ -484,14 +484,14 @@ protected void inject(Object bean, String beanName, PropertyValues pvs) throws T
484484
value = resolvedCachedArgument(beanName, this.cachedFieldValue);
485485
}
486486
else {
487-
DependencyDescriptor descriptor = new DependencyDescriptor(field, this.required);
487+
DependencyDescriptor desc = new DependencyDescriptor(field, this.required);
488488
Set<String> autowiredBeanNames = new LinkedHashSet<String>(1);
489489
TypeConverter typeConverter = beanFactory.getTypeConverter();
490-
value = beanFactory.resolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter);
490+
value = beanFactory.resolveDependency(desc, beanName, autowiredBeanNames, typeConverter);
491491
synchronized (this) {
492492
if (!this.cached) {
493493
if (value != null || this.required) {
494-
this.cachedFieldValue = descriptor;
494+
this.cachedFieldValue = desc;
495495
registerDependentBeans(beanName, autowiredBeanNames);
496496
if (autowiredBeanNames.size() == 1) {
497497
String autowiredBeanName = autowiredBeanNames.iterator().next();

spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,6 @@
1616

1717
package org.springframework.beans.factory.annotation;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotNull;
21-
import static org.junit.Assert.assertNotSame;
22-
import static org.junit.Assert.assertNull;
23-
import static org.junit.Assert.assertSame;
24-
import static org.junit.Assert.assertTrue;
25-
import static org.junit.Assert.fail;
26-
2719
import java.io.Serializable;
2820
import java.lang.annotation.ElementType;
2921
import java.lang.annotation.Retention;
@@ -33,6 +25,7 @@
3325
import java.util.Map;
3426

3527
import org.junit.Test;
28+
3629
import org.springframework.beans.factory.BeanCreationException;
3730
import org.springframework.beans.factory.BeanFactory;
3831
import org.springframework.beans.factory.FactoryBean;
@@ -49,16 +42,15 @@
4942
import org.springframework.tests.sample.beans.TestBean;
5043
import org.springframework.util.SerializationTestUtils;
5144

45+
import static org.junit.Assert.*;
5246

5347
/**
54-
* Unit tests for {@link AutowiredAnnotationBeanPostProcessor}.
55-
*
5648
* @author Juergen Hoeller
5749
* @author Mark Fisher
5850
* @author Sam Brannen
5951
* @author Chris Beams
6052
*/
61-
public final class AutowiredAnnotationBeanPostProcessorTests {
53+
public class AutowiredAnnotationBeanPostProcessorTests {
6254

6355
@Test
6456
public void testIncompleteBeanDefinition() {
@@ -963,7 +955,6 @@ public static class ResourceInjectionBean {
963955

964956
private TestBean testBean2;
965957

966-
967958
@Autowired
968959
public void setTestBean2(TestBean testBean2) {
969960
if (this.testBean2 != null) {

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object
287287
"result in a failure to process annotations such as @Autowired, " +
288288
"@Resource and @PostConstruct within the method's declaring " +
289289
"@Configuration class. Add the 'static' modifier to this method to avoid " +
290-
"these container lifecycle issues; see @Bean Javadoc for complete details",
290+
"these container lifecycle issues; see @Bean javadoc for complete details",
291291
beanMethod.getDeclaringClass().getSimpleName(), beanMethod.getName()));
292292
}
293293
return cglibMethodProxy.invokeSuper(enhancedConfigInstance, beanMethodArgs);

spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public String toString() {
194194
}
195195

196196

197-
// subclassing hooks
197+
// Protected template methods
198198

199199
/**
200200
* Template method to convert a null source.

spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java

+27-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@
5757
* @author Keith Donald
5858
* @author Juergen Hoeller
5959
* @author Phillip Webb
60+
* @author David Haraburda
6061
*/
6162
public class GenericConversionServiceTests {
6263

6364
private GenericConversionService conversionService = new GenericConversionService();
6465

66+
6567
@Test
6668
public void canConvert() {
6769
assertFalse(conversionService.canConvert(String.class, Integer.class));
@@ -749,6 +751,13 @@ public void testEnumToStringConversion() {
749751
assertEquals("A", result);
750752
}
751753

754+
@Test
755+
public void testSubclassOfEnumToString() throws Exception {
756+
conversionService.addConverter(new EnumToStringConverter(conversionService));
757+
String result = conversionService.convert(EnumWithSubclass.FIRST, String.class);
758+
assertEquals("FIRST", result);
759+
}
760+
752761
@Test
753762
public void testEnumWithInterfaceToStringConversion() {
754763
// SPR-9692
@@ -846,6 +855,7 @@ public void rawCollectionAsSource() throws Exception {
846855
@ExampleAnnotation
847856
public String annotatedString;
848857

858+
849859
@Retention(RetentionPolicy.RUNTIME)
850860
public static @interface ExampleAnnotation {
851861
}
@@ -888,8 +898,7 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
888898
}
889899

890900
@Override
891-
public Object convert(Object source, TypeDescriptor sourceType,
892-
TypeDescriptor targetType) {
901+
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
893902
return null;
894903
}
895904

@@ -932,6 +941,7 @@ interface MyEnumInterface {
932941
String getCode();
933942
}
934943

944+
935945
public static enum MyEnum implements MyEnumInterface {
936946

937947
A {
@@ -943,6 +953,17 @@ public String getCode() {
943953
}
944954

945955

956+
public enum EnumWithSubclass {
957+
958+
FIRST {
959+
@Override
960+
public String toString() {
961+
return "1st";
962+
}
963+
}
964+
}
965+
966+
946967
public static class MyStringToRawCollectionConverter implements Converter<String, Collection> {
947968

948969
@Override
@@ -951,6 +972,7 @@ public Collection convert(String source) {
951972
}
952973
}
953974

975+
954976
public static class MyStringToGenericCollectionConverter implements Converter<String, Collection<?>> {
955977

956978
@Override
@@ -959,6 +981,7 @@ public Collection<?> convert(String source) {
959981
}
960982
}
961983

984+
962985
private static class MyEnumInterfaceToStringConverter<T extends MyEnumInterface> implements Converter<T, String> {
963986

964987
@Override
@@ -967,6 +990,7 @@ public String convert(T source) {
967990
}
968991
}
969992

993+
970994
public static class MyStringToStringCollectionConverter implements Converter<String, Collection<String>> {
971995

972996
@Override
@@ -975,6 +999,7 @@ public Collection<String> convert(String source) {
975999
}
9761000
}
9771001

1002+
9781003
public static class MyStringToIntegerCollectionConverter implements Converter<String, Collection<Integer>> {
9791004

9801005
@Override

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,6 +52,8 @@
5252
* exposed to allow for convenient access to the traditional
5353
* {@link org.springframework.jdbc.core.JdbcTemplate} methods.
5454
*
55+
* <p><b>NOTE: An instance of this class is thread-safe once configured.</b>
56+
*
5557
* @author Thomas Risberg
5658
* @author Juergen Hoeller
5759
* @since 2.0
@@ -320,7 +322,7 @@ public int[] batchUpdate(String sql, Map<String, ?>[] batchValues) {
320322
}
321323

322324
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
323-
ParsedSql parsedSql = this.getParsedSql(sql);
325+
ParsedSql parsedSql = getParsedSql(sql);
324326
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(parsedSql, batchArgs, getJdbcOperations());
325327
}
326328

spring-web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,8 @@
2323
import org.springframework.util.Assert;
2424

2525
/**
26-
* Abstract base for {@link ClientHttpRequest} that makes sure that headers and body are not written multiple times.
26+
* Abstract base for {@link ClientHttpRequest} that makes sure that headers
27+
* and body are not written multiple times.
2728
*
2829
* @author Arjen Poutsma
2930
* @since 3.0

spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,13 +27,13 @@
2727
import org.springframework.util.Assert;
2828

2929
/**
30-
* {@link ClientHttpRequestFactory} implementation that uses standard J2SE facilities.
30+
* {@link ClientHttpRequestFactory} implementation that uses standard JDK facilities.
3131
*
3232
* @author Arjen Poutsma
3333
* @author Juergen Hoeller
3434
* @since 3.0
3535
* @see java.net.HttpURLConnection
36-
* @see CommonsClientHttpRequestFactory
36+
* @see HttpComponentsClientHttpRequestFactory
3737
*/
3838
public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory {
3939

@@ -107,14 +107,12 @@ public void setReadTimeout(int readTimeout) {
107107
}
108108

109109
/**
110-
* Set if the underlying URLConnection can be set to 'output streaming' mode. When
111-
* output streaming is enabled, authentication and redirection cannot be handled
112-
* automatically. If output streaming is disabled the
113-
* {@link HttpURLConnection#setFixedLengthStreamingMode(int)
114-
* setFixedLengthStreamingMode} and
115-
* {@link HttpURLConnection#setChunkedStreamingMode(int) setChunkedStreamingMode}
116-
* methods of the underlying connection will never be called.
117-
* <p>Default is {@code true}.
110+
* Set if the underlying URLConnection can be set to 'output streaming' mode.
111+
* Default is {@code true}.
112+
* <p>When output streaming is enabled, authentication and redirection cannot be handled automatically.
113+
* If output streaming is disabled, the {@link HttpURLConnection#setFixedLengthStreamingMode} and
114+
* {@link HttpURLConnection#setChunkedStreamingMode} methods of the underlying connection will never
115+
* be called.
118116
* @param outputStreaming if output streaming is enabled
119117
*/
120118
public void setOutputStreaming(boolean outputStreaming) {
@@ -129,8 +127,7 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO
129127
return new SimpleBufferingClientHttpRequest(connection, this.outputStreaming);
130128
}
131129
else {
132-
return new SimpleStreamingClientHttpRequest(connection, this.chunkSize,
133-
this.outputStreaming);
130+
return new SimpleStreamingClientHttpRequest(connection, this.chunkSize, this.outputStreaming);
134131
}
135132
}
136133

0 commit comments

Comments
 (0)