Skip to content

Commit c99a104

Browse files
committed
Polishing
1 parent 193c289 commit c99a104

File tree

9 files changed

+85
-77
lines changed

9 files changed

+85
-77
lines changed

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

Lines changed: 3 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-2018 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.
@@ -55,8 +55,8 @@
5555
* and obviates the need (<b>in part</b>) for a developer to code a method that
5656
* simply checks that all required properties have actually been set.
5757
*
58-
* <p>Please note that an 'init' method may still need to implemented (and may
59-
* still be desirable), because all that this class does is enforce that a
58+
* <p>Please note that an 'init' method may still need to be implemented (and may
59+
* still be desirable), because all that this class does is enforcing that a
6060
* 'required' property has actually been configured with a value. It does
6161
* <b>not</b> check anything else... In particular, it does not check that a
6262
* configured value is not {@code null}.

spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -265,7 +265,7 @@ else if (isTwoCharToken(TokenKind.SAFE_NAVI)) {
265265
raiseParseException(this.pos, SpelMessage.UNEXPECTED_ESCAPE_CHAR);
266266
break;
267267
default:
268-
throw new IllegalStateException("Cannot handle (" + Integer.valueOf(ch) + ") '" + ch + "'");
268+
throw new IllegalStateException("Cannot handle (" + (int) ch + ") '" + ch + "'");
269269
}
270270
}
271271
}

spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java

Lines changed: 18 additions & 13 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.
@@ -72,15 +72,15 @@ public void setValidationQuery(String validationQuery) {
7272

7373
/**
7474
* Set the interval between validation runs (in seconds).
75-
* Default is 1.
75+
* Default is {@value #DEFAULT_INTERVAL}.
7676
*/
7777
public void setInterval(int interval) {
7878
this.interval = interval;
7979
}
8080

8181
/**
8282
* Set the timeout (in seconds) after which a fatal exception
83-
* will be thrown. Default is 60.
83+
* will be thrown. Default is {@value #DEFAULT_TIMEOUT}.
8484
*/
8585
public void setTimeout(int timeout) {
8686
this.timeout = timeout;
@@ -94,11 +94,12 @@ public void setTimeout(int timeout) {
9494
*/
9595
@Override
9696
public void afterPropertiesSet() {
97-
if (this.dataSource == null) {
98-
throw new IllegalArgumentException("dataSource is required");
97+
DataSource dataSource = this.dataSource;
98+
if (dataSource == null) {
99+
throw new IllegalArgumentException("Property 'dataSource' is required");
99100
}
100101
if (this.validationQuery == null) {
101-
throw new IllegalArgumentException("validationQuery is required");
102+
throw new IllegalArgumentException("Property 'validationQuery' is required");
102103
}
103104

104105
try {
@@ -111,18 +112,22 @@ public void afterPropertiesSet() {
111112
Connection con = null;
112113
Statement stmt = null;
113114
try {
114-
con = this.dataSource.getConnection();
115+
con = dataSource.getConnection();
115116
stmt = con.createStatement();
116117
stmt.execute(this.validationQuery);
117118
validated = true;
118119
}
119120
catch (SQLException ex) {
120121
latestEx = ex;
121-
logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex);
122-
float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000;
123-
if (rest > this.interval) {
124-
logger.warn("Database has not started up yet - retrying in " + this.interval +
125-
" seconds (timeout in " + rest + " seconds)");
122+
if (logger.isDebugEnabled()) {
123+
logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex);
124+
}
125+
if (logger.isWarnEnabled()) {
126+
float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000;
127+
if (rest > this.interval) {
128+
logger.warn("Database has not started up yet - retrying in " + this.interval +
129+
" seconds (timeout in " + rest + " seconds)");
130+
}
126131
}
127132
}
128133
finally {
@@ -140,8 +145,8 @@ public void afterPropertiesSet() {
140145
"Database has not started up within " + this.timeout + " seconds", latestEx);
141146
}
142147

143-
float duration = (System.currentTimeMillis() - beginTime) / 1000;
144148
if (logger.isInfoEnabled()) {
149+
float duration = ((float) (System.currentTimeMillis() - beginTime)) / 1000;
145150
logger.info("Database startup detected after " + duration + " seconds");
146151
}
147152
}

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ public HttpHeaders() {
400400
* Private constructor that can create read-only {@code HttpHeader} instances.
401401
*/
402402
private HttpHeaders(Map<String, List<String>> headers, boolean readOnly) {
403-
Assert.notNull(headers, "'headers' must not be null");
404403
if (readOnly) {
405404
Map<String, List<String>> map =
406405
new LinkedCaseInsensitiveMap<List<String>>(headers.size(), Locale.ENGLISH);
@@ -1319,6 +1318,7 @@ public String toString() {
13191318
* Return a {@code HttpHeaders} object that can only be read, not written to.
13201319
*/
13211320
public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers) {
1321+
Assert.notNull(headers, "HttpHeaders must not be null");
13221322
return new HttpHeaders(headers, true);
13231323
}
13241324

spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExceptionResolver.java

Lines changed: 3 additions & 3 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-2018 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.
@@ -44,8 +44,8 @@ public interface HandlerExceptionResolver {
4444
* @param handler the executed handler, or {@code null} if none chosen at the
4545
* time of the exception (for example, if multipart resolution failed)
4646
* @param ex the exception that got thrown during handler execution
47-
* @return a corresponding {@code ModelAndView} to forward to, or {@code null}
48-
* for default processing
47+
* @return a corresponding {@code ModelAndView} to forward to,
48+
* or {@code null} for default processing in the resolution chain
4949
*/
5050
ModelAndView resolveException(
5151
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex);

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java

Lines changed: 7 additions & 7 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-2018 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.
@@ -17,7 +17,6 @@
1717
package org.springframework.web.servlet.handler;
1818

1919
import java.util.Set;
20-
2120
import javax.servlet.http.HttpServletRequest;
2221
import javax.servlet.http.HttpServletResponse;
2322

@@ -125,8 +124,8 @@ public void setPreventResponseCaching(boolean preventResponseCaching) {
125124
* to the {@link #doResolveException} template method.
126125
*/
127126
@Override
128-
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
129-
Object handler, Exception ex) {
127+
public ModelAndView resolveException(
128+
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
130129

131130
if (shouldApplyTo(request, handler)) {
132131
if (this.logger.isDebugEnabled()) {
@@ -237,9 +236,10 @@ protected void preventCaching(HttpServletResponse response) {
237236
* @param handler the executed handler, or {@code null} if none chosen at the time
238237
* of the exception (for example, if multipart resolution failed)
239238
* @param ex the exception that got thrown during handler execution
240-
* @return a corresponding {@code ModelAndView} to forward to, or {@code null} for default processing
239+
* @return a corresponding {@code ModelAndView} to forward to,
240+
* or {@code null} for default processing in the resolution chain
241241
*/
242-
protected abstract ModelAndView doResolveException(HttpServletRequest request,
243-
HttpServletResponse response, Object handler, Exception ex);
242+
protected abstract ModelAndView doResolveException(
243+
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex);
244244

245245
}

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java

Lines changed: 5 additions & 4 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-2018 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.
@@ -170,11 +170,12 @@ public void setExceptionAttribute(String exceptionAttribute) {
170170
* @param handler the executed handler, or {@code null} if none chosen at the time
171171
* of the exception (for example, if multipart resolution failed)
172172
* @param ex the exception that got thrown during handler execution
173-
* @return a corresponding ModelAndView to forward to, or {@code null} for default processing
173+
* @return a corresponding {@code ModelAndView} to forward to,
174+
* or {@code null} for default processing in the resolution chain
174175
*/
175176
@Override
176-
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
177-
Object handler, Exception ex) {
177+
protected ModelAndView doResolveException(
178+
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
178179

179180
// Expose ModelAndView for chosen error view.
180181
String viewName = determineViewName(ex, request);

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -59,16 +59,16 @@ public void setMessageSource(MessageSource messageSource) {
5959

6060

6161
@Override
62-
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
63-
Object handler, Exception ex) {
62+
protected ModelAndView doResolveException(
63+
HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
6464

65-
ResponseStatus responseStatus = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class);
66-
if (responseStatus != null) {
65+
ResponseStatus status = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class);
66+
if (status != null) {
6767
try {
68-
return resolveResponseStatus(responseStatus, request, response, handler, ex);
68+
return resolveResponseStatus(status, request, response, handler, ex);
6969
}
7070
catch (Exception resolveEx) {
71-
logger.warn("Handling of @ResponseStatus resulted in Exception", resolveEx);
71+
logger.warn("ResponseStatus handling resulted in exception", resolveEx);
7272
}
7373
}
7474
else if (ex.getCause() instanceof Exception) {
@@ -79,7 +79,7 @@ else if (ex.getCause() instanceof Exception) {
7979
}
8080

8181
/**
82-
* Template method that handles {@link ResponseStatus @ResponseStatus} annotation.
82+
* Template method that handles the {@link ResponseStatus @ResponseStatus} annotation.
8383
* <p>The default implementation sends a response error using
8484
* {@link HttpServletResponse#sendError(int)} or
8585
* {@link HttpServletResponse#sendError(int, String)} if the annotation has a
@@ -88,11 +88,9 @@ else if (ex.getCause() instanceof Exception) {
8888
* @param request current HTTP request
8989
* @param response current HTTP response
9090
* @param handler the executed handler, or {@code null} if none chosen at the
91-
* time of the exception (for example, if multipart resolution failed)
92-
* @param ex the exception that got thrown during handler execution or the
93-
* exception that has the ResponseStatus annotation if found on the cause.
94-
* @return a corresponding ModelAndView to forward to, or {@code null}
95-
* for default processing
91+
* time of the exception, e.g. if multipart resolution failed
92+
* @param ex the exception
93+
* @return an empty ModelAndView, i.e. exception resolved
9694
*/
9795
protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request,
9896
HttpServletResponse response, Object handler, Exception ex) throws Exception {

0 commit comments

Comments
 (0)