Skip to content

Commit f8b729a

Browse files
committed
Polishing
1 parent b39e66b commit f8b729a

File tree

24 files changed

+157
-139
lines changed

24 files changed

+157
-139
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
241241
if (requiredConstructor != null) {
242242
throw new BeanCreationException(beanName,
243243
"Invalid autowire-marked constructor: " + candidate +
244-
". Found another constructor with 'required' Autowired annotation: " +
244+
". Found constructor with 'required' Autowired annotation already: " +
245245
requiredConstructor);
246246
}
247247
if (candidate.getParameterTypes().length == 0) {
@@ -253,7 +253,7 @@ public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, Strin
253253
if (!candidates.isEmpty()) {
254254
throw new BeanCreationException(beanName,
255255
"Invalid autowire-marked constructors: " + candidates +
256-
". Found another constructor with 'required' Autowired annotation: " +
256+
". Found constructor with 'required' Autowired annotation: " +
257257
candidate);
258258
}
259259
requiredConstructor = candidate;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2610,7 +2610,7 @@ public interface GenericInterface1<T> {
26102610
}
26112611

26122612

2613-
public static class GenericInterface1Impl<T> implements GenericInterface1<T>{
2613+
public static class GenericInterface1Impl<T> implements GenericInterface1<T> {
26142614

26152615
@Autowired
26162616
private GenericInterface2<T> gi2;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public String toString() {
200200
}
201201

202202

203-
// subclassing hooks
203+
// Protected template methods
204204

205205
/**
206206
* Template method to convert a null source.
@@ -548,7 +548,7 @@ private List<Class<?>> getClassHierarchy(Class<?> type) {
548548
Class<?> candidate = hierarchy.get(i);
549549
candidate = (array ? candidate.getComponentType() : ClassUtils.resolvePrimitiveIfNecessary(candidate));
550550
Class<?> superclass = candidate.getSuperclass();
551-
if (candidate.getSuperclass() != null && superclass != Object.class) {
551+
if (superclass != null && superclass != Object.class) {
552552
addToClassHierarchy(i + 1, candidate.getSuperclass(), array, hierarchy, visited);
553553
}
554554
for (Class<?> implementedInterface : candidate.getInterfaces()) {
@@ -563,6 +563,7 @@ private List<Class<?>> getClassHierarchy(Class<?> type) {
563563

564564
private void addToClassHierarchy(int index, Class<?> type, boolean asArray,
565565
List<Class<?>> hierarchy, Set<Class<?>> visited) {
566+
566567
if (asArray) {
567568
type = Array.newInstance(type, 0).getClass();
568569
}

spring-core/src/main/java/org/springframework/util/SocketUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ public static SortedSet<Integer> findAvailableUdpPorts(int numRequested, int min
194194
private static enum SocketType {
195195

196196
TCP {
197-
198197
@Override
199198
protected boolean isPortAvailable(int port) {
200199
try {
@@ -209,7 +208,6 @@ protected boolean isPortAvailable(int port) {
209208
},
210209

211210
UDP {
212-
213211
@Override
214212
protected boolean isPortAvailable(int port) {
215213
try {

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

Lines changed: 27 additions & 2 deletions
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
@@ -850,6 +859,7 @@ public void rawCollectionAsSource() throws Exception {
850859
@ExampleAnnotation
851860
public String annotatedString;
852861

862+
853863
@Retention(RetentionPolicy.RUNTIME)
854864
public static @interface ExampleAnnotation {
855865
}
@@ -892,8 +902,7 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
892902
}
893903

894904
@Override
895-
public Object convert(Object source, TypeDescriptor sourceType,
896-
TypeDescriptor targetType) {
905+
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
897906
return null;
898907
}
899908

@@ -936,6 +945,7 @@ interface MyEnumInterface {
936945
String getCode();
937946
}
938947

948+
939949
public static enum MyEnum implements MyEnumInterface {
940950

941951
A {
@@ -947,6 +957,17 @@ public String getCode() {
947957
}
948958

949959

960+
public enum EnumWithSubclass {
961+
962+
FIRST {
963+
@Override
964+
public String toString() {
965+
return "1st";
966+
}
967+
}
968+
}
969+
970+
950971
public static class MyStringToRawCollectionConverter implements Converter<String, Collection> {
951972

952973
@Override
@@ -955,6 +976,7 @@ public Collection convert(String source) {
955976
}
956977
}
957978

979+
958980
public static class MyStringToGenericCollectionConverter implements Converter<String, Collection<?>> {
959981

960982
@Override
@@ -963,6 +985,7 @@ public Collection<?> convert(String source) {
963985
}
964986
}
965987

988+
966989
private static class MyEnumInterfaceToStringConverter<T extends MyEnumInterface> implements Converter<T, String> {
967990

968991
@Override
@@ -971,6 +994,7 @@ public String convert(T source) {
971994
}
972995
}
973996

997+
974998
public static class MyStringToStringCollectionConverter implements Converter<String, Collection<String>> {
975999

9761000
@Override
@@ -979,6 +1003,7 @@ public Collection<String> convert(String source) {
9791003
}
9801004
}
9811005

1006+
9821007
public static class MyStringToIntegerCollectionConverter implements Converter<String, Collection<Integer>> {
9831008

9841009
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public int[] batchUpdate(String sql, Map<String, ?>[] batchValues) {
357357

358358
@Override
359359
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs) {
360-
ParsedSql parsedSql = this.getParsedSql(sql);
360+
ParsedSql parsedSql = getParsedSql(sql);
361361
return NamedParameterBatchUpdateUtils.executeBatchUpdateWithNamedParameters(parsedSql, batchArgs, getJdbcOperations());
362362
}
363363

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/Header.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -40,8 +40,7 @@
4040

4141
/**
4242
* Whether the header is required.
43-
* <p>
44-
* Default is {@code true}, leading to an exception if the header missing. Switch this
43+
* <p>Default is {@code true}, leading to an exception if the header missing. Switch this
4544
* to {@code false} if you prefer a {@code null} in case of the header missing.
4645
*/
4746
boolean required() default true;

spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolverTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public void resolveArgument() throws Exception {
8888

8989
@Test
9090
public void resolveArgumentNativeHeader() throws Exception {
91-
9291
TestMessageHeaderAccessor headers = new TestMessageHeaderAccessor();
9392
headers.setNativeHeader("param1", "foo");
9493
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build();
@@ -98,7 +97,6 @@ public void resolveArgumentNativeHeader() throws Exception {
9897

9998
@Test
10099
public void resolveArgumentNativeHeaderAmbiguity() throws Exception {
101-
102100
TestMessageHeaderAccessor headers = new TestMessageHeaderAccessor();
103101
headers.setHeader("param1", "foo");
104102
headers.setNativeHeader("param1", "native-foo");

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

Lines changed: 4 additions & 4 deletions
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.
@@ -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
@@ -55,8 +56,7 @@ public final ClientHttpResponse execute() throws IOException {
5556
}
5657

5758
/**
58-
* Asserts that this request has not been {@linkplain #execute() executed} yet.
59-
*
59+
* Assert that this request has not been {@linkplain #execute() executed} yet.
6060
* @throws IllegalStateException if this request has been executed
6161
*/
6262
protected void assertNotExecuted() {

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

Lines changed: 14 additions & 19 deletions
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.
@@ -28,16 +28,15 @@
2828
import org.springframework.util.Assert;
2929

3030
/**
31-
* {@link ClientHttpRequestFactory} implementation that uses standard J2SE facilities.
31+
* {@link ClientHttpRequestFactory} implementation that uses standard JDK facilities.
3232
*
3333
* @author Arjen Poutsma
3434
* @author Juergen Hoeller
3535
* @since 3.0
3636
* @see java.net.HttpURLConnection
3737
* @see HttpComponentsClientHttpRequestFactory
3838
*/
39-
public class SimpleClientHttpRequestFactory
40-
implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory {
39+
public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory, AsyncClientHttpRequestFactory {
4140

4241
private static final int DEFAULT_CHUNK_SIZE = 4096;
4342

@@ -111,30 +110,28 @@ public void setReadTimeout(int readTimeout) {
111110
}
112111

113112
/**
114-
* Set if the underlying URLConnection can be set to 'output streaming' mode. When
115-
* output streaming is enabled, authentication and redirection cannot be handled
116-
* automatically. If output streaming is disabled the
117-
* {@link HttpURLConnection#setFixedLengthStreamingMode(int)
118-
* setFixedLengthStreamingMode} and
119-
* {@link HttpURLConnection#setChunkedStreamingMode(int) setChunkedStreamingMode}
120-
* methods of the underlying connection will never be called.
121-
* <p>Default is {@code true}.
113+
* Set if the underlying URLConnection can be set to 'output streaming' mode.
114+
* Default is {@code true}.
115+
* <p>When output streaming is enabled, authentication and redirection cannot be handled automatically.
116+
* If output streaming is disabled, the {@link HttpURLConnection#setFixedLengthStreamingMode} and
117+
* {@link HttpURLConnection#setChunkedStreamingMode} methods of the underlying connection will never
118+
* be called.
122119
* @param outputStreaming if output streaming is enabled
123120
*/
124121
public void setOutputStreaming(boolean outputStreaming) {
125122
this.outputStreaming = outputStreaming;
126123
}
127124

128125
/**
129-
* Sets the task executor for this request factory. Setting this property is required
130-
* for {@linkplain #createAsyncRequest(URI, HttpMethod) creating asynchronous
131-
* request}.
126+
* Set the task executor for this request factory. Setting this property is required
127+
* for {@linkplain #createAsyncRequest(URI, HttpMethod) creating asynchronous requests}.
132128
* @param taskExecutor the task executor
133129
*/
134130
public void setTaskExecutor(AsyncListenableTaskExecutor taskExecutor) {
135131
this.taskExecutor = taskExecutor;
136132
}
137133

134+
138135
@Override
139136
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
140137
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
@@ -153,10 +150,8 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO
153150
* is required before calling this method.
154151
*/
155152
@Override
156-
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
157-
throws IOException {
158-
Assert.state(this.taskExecutor != null, "Asynchronous execution requires an " +
159-
"AsyncTaskExecutor to be set");
153+
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException {
154+
Assert.state(this.taskExecutor != null, "Asynchronous execution requires an AsyncTaskExecutor to be set");
160155
HttpURLConnection connection = openConnection(uri.toURL(), this.proxy);
161156
prepareConnection(connection, httpMethod.name());
162157
if (this.bufferRequestBody) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -24,7 +24,7 @@
2424
import org.springframework.util.StringUtils;
2525

2626
/**
27-
* {@link ClientHttpResponse} implementation that uses standard J2SE facilities.
27+
* {@link ClientHttpResponse} implementation that uses standard JDK facilities.
2828
* Obtained via {@link SimpleBufferingClientHttpRequest#execute()} and
2929
* {@link SimpleStreamingClientHttpRequest#execute()}.
3030
*

spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -48,6 +48,7 @@ public AbstractCookieValueMethodArgumentResolver(ConfigurableBeanFactory beanFac
4848
super(beanFactory);
4949
}
5050

51+
5152
@Override
5253
public boolean supportsParameter(MethodParameter parameter) {
5354
return parameter.hasParameterAnnotation(CookieValue.class);
@@ -60,16 +61,17 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
6061
}
6162

6263
@Override
63-
protected void handleMissingValue(String cookieName, MethodParameter param) throws ServletRequestBindingException {
64-
String paramType = param.getParameterType().getName();
65-
throw new ServletRequestBindingException(
66-
"Missing cookie named '" + cookieName + "' for method parameter type [" + paramType + "]");
64+
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException {
65+
throw new ServletRequestBindingException("Missing cookie '" + name +
66+
"' for method parameter of type " + parameter.getParameterType().getSimpleName());
6767
}
6868

69+
6970
private static class CookieValueNamedValueInfo extends NamedValueInfo {
7071

7172
private CookieValueNamedValueInfo(CookieValue annotation) {
7273
super(annotation.value(), annotation.required(), annotation.defaultValue());
7374
}
7475
}
76+
7577
}

spring-web/src/main/java/org/springframework/web/method/annotation/AbstractNamedValueMethodArgumentResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ else if (namedValueInfo.required) {
9696
}
9797
arg = handleNullValue(namedValueInfo.name, arg, paramType);
9898
}
99-
else if ("".equals(arg) && (namedValueInfo.defaultValue != null)) {
99+
else if ("".equals(arg) && namedValueInfo.defaultValue != null) {
100100
arg = resolveDefaultValue(namedValueInfo.defaultValue);
101101
}
102102

0 commit comments

Comments
 (0)