Skip to content

Commit 17f42fc

Browse files
committed
Polishing
1 parent fa2c377 commit 17f42fc

File tree

8 files changed

+47
-24
lines changed

8 files changed

+47
-24
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -232,6 +232,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
232232
/**
233233
* Return whether this a <b>Prototype</b>, with an independent instance
234234
* returned for each call.
235+
* @since 3.0
235236
* @see #SCOPE_PROTOTYPE
236237
*/
237238
boolean isPrototype();

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public Object getObject() throws BeansException {
366366
}
367367

368368
// Check if required type matches the type of the actual bean instance.
369-
if (requiredType != null && bean != null && !requiredType.isAssignableFrom(bean.getClass())) {
369+
if (requiredType != null && bean != null && !requiredType.isInstance(bean)) {
370370
try {
371371
return getTypeConverter().convertIfNecessary(bean, requiredType);
372372
}

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractExceptionHandlerMethodResolver.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -66,7 +66,9 @@ protected static List<Class<? extends Throwable>> getExceptionsFromMethodSignatu
6666
result.add((Class<? extends Throwable>) paramType);
6767
}
6868
}
69-
Assert.notEmpty(result, "No exception types mapped to {" + method + "}");
69+
if (result.isEmpty()) {
70+
throw new IllegalStateException("No exception types mapped to " + method);
71+
}
7072
return result;
7173
}
7274

@@ -75,7 +77,7 @@ protected static List<Class<? extends Throwable>> getExceptionsFromMethodSignatu
7577
* Whether the contained type has any exception mappings.
7678
*/
7779
public boolean hasExceptionMappings() {
78-
return (this.mappedMethods.size() > 0);
80+
return !this.mappedMethods.isEmpty();
7981
}
8082

8183
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -94,7 +94,7 @@ public void ambiguousExceptionMapping() {
9494
new AnnotationExceptionHandlerMethodResolver(AmbiguousController.class);
9595
}
9696

97-
@Test(expected = IllegalArgumentException.class)
97+
@Test(expected = IllegalStateException.class)
9898
public void noExceptionMapping() {
9999
new AnnotationExceptionHandlerMethodResolver(NoExceptionController.class);
100100
}

spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ protected void doBind(MutablePropertyValues mpvs) {
201201
* @see #getFieldDefaultPrefix
202202
*/
203203
protected void checkFieldDefaults(MutablePropertyValues mpvs) {
204-
if (getFieldDefaultPrefix() != null) {
205-
String fieldDefaultPrefix = getFieldDefaultPrefix();
204+
String fieldDefaultPrefix = getFieldDefaultPrefix();
205+
if (fieldDefaultPrefix != null) {
206206
PropertyValue[] pvArray = mpvs.getPropertyValues();
207207
for (PropertyValue pv : pvArray) {
208208
if (pv.getName().startsWith(fieldDefaultPrefix)) {
@@ -228,8 +228,8 @@ protected void checkFieldDefaults(MutablePropertyValues mpvs) {
228228
* @see #getEmptyValue(String, Class)
229229
*/
230230
protected void checkFieldMarkers(MutablePropertyValues mpvs) {
231-
if (getFieldMarkerPrefix() != null) {
232-
String fieldMarkerPrefix = getFieldMarkerPrefix();
231+
String fieldMarkerPrefix = getFieldMarkerPrefix();
232+
if (fieldMarkerPrefix != null) {
233233
PropertyValue[] pvArray = mpvs.getPropertyValues();
234234
for (PropertyValue pv : pvArray) {
235235
if (pv.getName().startsWith(fieldMarkerPrefix)) {
@@ -246,7 +246,7 @@ protected void checkFieldMarkers(MutablePropertyValues mpvs) {
246246

247247
/**
248248
* Determine an empty value for the specified field.
249-
* <p>Default implementation returns:
249+
* <p>The default implementation returns:
250250
* <ul>
251251
* <li>{@code Boolean.FALSE} for boolean fields
252252
* <li>an empty array for array types
@@ -275,17 +275,20 @@ else if (Collection.class.isAssignableFrom(fieldType)) {
275275
else if (Map.class.isAssignableFrom(fieldType)) {
276276
return CollectionFactory.createMap(fieldType, 0);
277277
}
278-
} catch (IllegalArgumentException exc) {
279-
return null;
278+
}
279+
catch (IllegalArgumentException ex) {
280+
if (logger.isDebugEnabled()) {
281+
logger.debug("Failed to create default value - falling back to null: " + ex.getMessage());
282+
}
280283
}
281284
}
282-
// Default value: try null.
285+
// Default value: null.
283286
return null;
284287
}
285288

286289
/**
287290
* Bind all multipart files contained in the given request, if any
288-
* (in case of a multipart request).
291+
* (in case of a multipart request). To be called by subclasses.
289292
* <p>Multipart files will only be added to the property values if they
290293
* are not empty or if we're configured to bind empty multipart files too.
291294
* @param multipartFiles Map of field name String to MultipartFile object

spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -36,7 +36,7 @@
3636
* the Exception instance as the concurrent result. Such exceptions will then
3737
* be processed through the {@code HandlerExceptionResolver} mechanism.
3838
*
39-
* <p>The {@link #handleTimeout(NativeWebRequest, Callable) afterTimeout} method
39+
* <p>The {@link #handleTimeout(NativeWebRequest, Callable) handleTimeout} method
4040
* can select a value to be used to resume processing.
4141
*
4242
* @author Rossen Stoyanchev
@@ -45,9 +45,20 @@
4545
*/
4646
public interface CallableProcessingInterceptor {
4747

48-
static final Object RESULT_NONE = new Object();
48+
/**
49+
* Constant indicating that no result has been determined by this
50+
* interceptor, giving subsequent interceptors a chance.
51+
* @see #handleTimeout
52+
*/
53+
Object RESULT_NONE = new Object();
54+
55+
/**
56+
* Constant indicating that the response has been handled by this interceptor
57+
* without a result and that no further interceptors are to be invoked.
58+
* @see #handleTimeout
59+
*/
60+
Object RESPONSE_HANDLED = new Object();
4961

50-
static final Object RESPONSE_HANDLED = new Object();
5162

5263
/**
5364
* Invoked <em>before</em> the start of concurrent handling in the original

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -94,7 +94,9 @@ private List<Class<? extends Throwable>> detectExceptionMappings(Method method)
9494
}
9595
}
9696
}
97-
Assert.notEmpty(result, "No exception types mapped to {" + method + "}");
97+
if (result.isEmpty()) {
98+
throw new IllegalStateException("No exception types mapped to " + method);
99+
}
98100
return result;
99101
}
100102

spring-web/src/test/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolverTests.java

Lines changed: 6 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-2017 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.
@@ -88,11 +88,12 @@ public void ambiguousExceptionMapping() {
8888
new ExceptionHandlerMethodResolver(AmbiguousController.class);
8989
}
9090

91-
@Test(expected = IllegalArgumentException.class)
91+
@Test(expected = IllegalStateException.class)
9292
public void noExceptionMapping() {
9393
new ExceptionHandlerMethodResolver(NoExceptionController.class);
9494
}
9595

96+
9697
@Controller
9798
static class ExceptionController {
9899

@@ -111,6 +112,7 @@ public void handleIllegalArgumentException(IllegalArgumentException exception) {
111112
}
112113
}
113114

115+
114116
@Controller
115117
static class InheritedController extends ExceptionController {
116118

@@ -119,6 +121,7 @@ public void handleIOException() {
119121
}
120122
}
121123

124+
122125
@Controller
123126
static class AmbiguousController {
124127

@@ -136,6 +139,7 @@ public String handle2(IllegalArgumentException ex) {
136139
}
137140
}
138141

142+
139143
@Controller
140144
static class NoExceptionController {
141145

0 commit comments

Comments
 (0)