diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java index 0d7eb6ee3b..31c0352879 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,8 +55,8 @@ import org.springframework.util.Assert; * and obviates the need (in part) for a developer to code a method that * simply checks that all required properties have actually been set. * - *

Please note that an 'init' method may still need to implemented (and may - * still be desirable), because all that this class does is enforce that a + *

Please note that an 'init' method may still need to be implemented (and may + * still be desirable), because all that this class does is enforcing that a * 'required' property has actually been configured with a value. It does * not check anything else... In particular, it does not check that a * configured value is not {@code null}. diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java index bcd7ea7806..7b7829b8f5 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -265,7 +265,7 @@ class Tokenizer { raiseParseException(this.pos, SpelMessage.UNEXPECTED_ESCAPE_CHAR); break; default: - throw new IllegalStateException("Cannot handle (" + Integer.valueOf(ch) + ") '" + ch + "'"); + throw new IllegalStateException("Cannot handle (" + (int) ch + ") '" + ch + "'"); } } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java index e5b11349f8..c6249a3115 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,7 +72,7 @@ public class DatabaseStartupValidator implements InitializingBean { /** * Set the interval between validation runs (in seconds). - * Default is 1. + * Default is {@value #DEFAULT_INTERVAL}. */ public void setInterval(int interval) { this.interval = interval; @@ -80,7 +80,7 @@ public class DatabaseStartupValidator implements InitializingBean { /** * Set the timeout (in seconds) after which a fatal exception - * will be thrown. Default is 60. + * will be thrown. Default is {@value #DEFAULT_TIMEOUT}. */ public void setTimeout(int timeout) { this.timeout = timeout; @@ -94,11 +94,12 @@ public class DatabaseStartupValidator implements InitializingBean { */ @Override public void afterPropertiesSet() { - if (this.dataSource == null) { - throw new IllegalArgumentException("dataSource is required"); + DataSource dataSource = this.dataSource; + if (dataSource == null) { + throw new IllegalArgumentException("Property 'dataSource' is required"); } if (this.validationQuery == null) { - throw new IllegalArgumentException("validationQuery is required"); + throw new IllegalArgumentException("Property 'validationQuery' is required"); } try { @@ -111,18 +112,22 @@ public class DatabaseStartupValidator implements InitializingBean { Connection con = null; Statement stmt = null; try { - con = this.dataSource.getConnection(); + con = dataSource.getConnection(); stmt = con.createStatement(); stmt.execute(this.validationQuery); validated = true; } catch (SQLException ex) { latestEx = ex; - logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex); - float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000; - if (rest > this.interval) { - logger.warn("Database has not started up yet - retrying in " + this.interval + - " seconds (timeout in " + rest + " seconds)"); + if (logger.isDebugEnabled()) { + logger.debug("Validation query [" + this.validationQuery + "] threw exception", ex); + } + if (logger.isWarnEnabled()) { + float rest = ((float) (deadLine - System.currentTimeMillis())) / 1000; + if (rest > this.interval) { + logger.warn("Database has not started up yet - retrying in " + this.interval + + " seconds (timeout in " + rest + " seconds)"); + } } } finally { @@ -140,8 +145,8 @@ public class DatabaseStartupValidator implements InitializingBean { "Database has not started up within " + this.timeout + " seconds", latestEx); } - float duration = (System.currentTimeMillis() - beginTime) / 1000; if (logger.isInfoEnabled()) { + float duration = ((float) (System.currentTimeMillis() - beginTime)) / 1000; logger.info("Database startup detected after " + duration + " seconds"); } } diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index 9f74a8978b..517c67e00c 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -400,7 +400,6 @@ public class HttpHeaders implements MultiValueMap, Serializable * Private constructor that can create read-only {@code HttpHeader} instances. */ private HttpHeaders(Map> headers, boolean readOnly) { - Assert.notNull(headers, "'headers' must not be null"); if (readOnly) { Map> map = new LinkedCaseInsensitiveMap>(headers.size(), Locale.ENGLISH); @@ -1319,6 +1318,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * Return a {@code HttpHeaders} object that can only be read, not written to. */ public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers) { + Assert.notNull(headers, "HttpHeaders must not be null"); return new HttpHeaders(headers, true); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExceptionResolver.java index d7d1b6d9b5..ee9815e56e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,8 +44,8 @@ public interface HandlerExceptionResolver { * @param handler the executed handler, or {@code null} if none chosen at the * time of the exception (for example, if multipart resolution failed) * @param ex the exception that got thrown during handler execution - * @return a corresponding {@code ModelAndView} to forward to, or {@code null} - * for default processing + * @return a corresponding {@code ModelAndView} to forward to, + * or {@code null} for default processing in the resolution chain */ ModelAndView resolveException( HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java index 50997f55bd..71a941d748 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package org.springframework.web.servlet.handler; import java.util.Set; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -125,8 +124,8 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * to the {@link #doResolveException} template method. */ @Override - public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, - Object handler, Exception ex) { + public ModelAndView resolveException( + HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { if (shouldApplyTo(request, handler)) { if (this.logger.isDebugEnabled()) { @@ -237,9 +236,10 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * @param handler the executed handler, or {@code null} if none chosen at the time * of the exception (for example, if multipart resolution failed) * @param ex the exception that got thrown during handler execution - * @return a corresponding {@code ModelAndView} to forward to, or {@code null} for default processing + * @return a corresponding {@code ModelAndView} to forward to, + * or {@code null} for default processing in the resolution chain */ - protected abstract ModelAndView doResolveException(HttpServletRequest request, - HttpServletResponse response, Object handler, Exception ex); + protected abstract ModelAndView doResolveException( + HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java index 7bf2c47e89..d0ccbd4ce0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleMappingExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -170,11 +170,12 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso * @param handler the executed handler, or {@code null} if none chosen at the time * of the exception (for example, if multipart resolution failed) * @param ex the exception that got thrown during handler execution - * @return a corresponding ModelAndView to forward to, or {@code null} for default processing + * @return a corresponding {@code ModelAndView} to forward to, + * or {@code null} for default processing in the resolution chain */ @Override - protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, - Object handler, Exception ex) { + protected ModelAndView doResolveException( + HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { // Expose ModelAndView for chosen error view. String viewName = determineViewName(ex, request); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java index ce3590aedf..80ee38523b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ResponseStatusExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,16 +59,16 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes @Override - protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, - Object handler, Exception ex) { + protected ModelAndView doResolveException( + HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { - ResponseStatus responseStatus = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class); - if (responseStatus != null) { + ResponseStatus status = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class); + if (status != null) { try { - return resolveResponseStatus(responseStatus, request, response, handler, ex); + return resolveResponseStatus(status, request, response, handler, ex); } catch (Exception resolveEx) { - logger.warn("Handling of @ResponseStatus resulted in Exception", resolveEx); + logger.warn("ResponseStatus handling resulted in exception", resolveEx); } } else if (ex.getCause() instanceof Exception) { @@ -79,7 +79,7 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes } /** - * Template method that handles {@link ResponseStatus @ResponseStatus} annotation. + * Template method that handles the {@link ResponseStatus @ResponseStatus} annotation. *

The default implementation sends a response error using * {@link HttpServletResponse#sendError(int)} or * {@link HttpServletResponse#sendError(int, String)} if the annotation has a @@ -88,11 +88,9 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen at the - * time of the exception (for example, if multipart resolution failed) - * @param ex the exception that got thrown during handler execution or the - * exception that has the ResponseStatus annotation if found on the cause. - * @return a corresponding ModelAndView to forward to, or {@code null} - * for default processing + * time of the exception, e.g. if multipart resolution failed + * @param ex the exception + * @return an empty ModelAndView, i.e. exception resolved */ protected ModelAndView resolveResponseStatus(ResponseStatus responseStatus, HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java index 456a27a525..56a35df001 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/DefaultHandlerExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,9 +52,9 @@ import org.springframework.web.servlet.NoHandlerFoundException; import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver; /** - * Default implementation of the {@link org.springframework.web.servlet.HandlerExceptionResolver - * HandlerExceptionResolver} interface that resolves standard Spring exceptions and translates - * them to corresponding HTTP status codes. + * The default implementation of the {@link org.springframework.web.servlet.HandlerExceptionResolver} + * interface, resolving standard Spring MVC exceptions and translating them to corresponding + * HTTP status codes. * *

This exception resolver is enabled by default in the common Spring * {@link org.springframework.web.servlet.DispatcherServlet}. @@ -102,63 +102,69 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @Override @SuppressWarnings("deprecation") - protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, - Object handler, Exception ex) { + protected ModelAndView doResolveException( + HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { try { if (ex instanceof org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) { - return handleNoSuchRequestHandlingMethod((org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) ex, + return handleNoSuchRequestHandlingMethod( + (org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) ex, request, response, handler); } else if (ex instanceof HttpRequestMethodNotSupportedException) { - return handleHttpRequestMethodNotSupported((HttpRequestMethodNotSupportedException) ex, request, - response, handler); + return handleHttpRequestMethodNotSupported( + (HttpRequestMethodNotSupportedException) ex, request, response, handler); } else if (ex instanceof HttpMediaTypeNotSupportedException) { - return handleHttpMediaTypeNotSupported((HttpMediaTypeNotSupportedException) ex, request, response, - handler); + return handleHttpMediaTypeNotSupported( + (HttpMediaTypeNotSupportedException) ex, request, response, handler); } else if (ex instanceof HttpMediaTypeNotAcceptableException) { - return handleHttpMediaTypeNotAcceptable((HttpMediaTypeNotAcceptableException) ex, request, response, - handler); + return handleHttpMediaTypeNotAcceptable( + (HttpMediaTypeNotAcceptableException) ex, request, response, handler); } else if (ex instanceof MissingPathVariableException) { - return handleMissingPathVariable((MissingPathVariableException) ex, request, - response, handler); + return handleMissingPathVariable( + (MissingPathVariableException) ex, request, response, handler); } else if (ex instanceof MissingServletRequestParameterException) { - return handleMissingServletRequestParameter((MissingServletRequestParameterException) ex, request, - response, handler); + return handleMissingServletRequestParameter( + (MissingServletRequestParameterException) ex, request, response, handler); } else if (ex instanceof ServletRequestBindingException) { - return handleServletRequestBindingException((ServletRequestBindingException) ex, request, response, - handler); + return handleServletRequestBindingException( + (ServletRequestBindingException) ex, request, response, handler); } else if (ex instanceof ConversionNotSupportedException) { - return handleConversionNotSupported((ConversionNotSupportedException) ex, request, response, handler); + return handleConversionNotSupported( + (ConversionNotSupportedException) ex, request, response, handler); } else if (ex instanceof TypeMismatchException) { - return handleTypeMismatch((TypeMismatchException) ex, request, response, handler); + return handleTypeMismatch( + (TypeMismatchException) ex, request, response, handler); } else if (ex instanceof HttpMessageNotReadableException) { - return handleHttpMessageNotReadable((HttpMessageNotReadableException) ex, request, response, handler); + return handleHttpMessageNotReadable( + (HttpMessageNotReadableException) ex, request, response, handler); } else if (ex instanceof HttpMessageNotWritableException) { - return handleHttpMessageNotWritable((HttpMessageNotWritableException) ex, request, response, handler); + return handleHttpMessageNotWritable( + (HttpMessageNotWritableException) ex, request, response, handler); } else if (ex instanceof MethodArgumentNotValidException) { - return handleMethodArgumentNotValidException((MethodArgumentNotValidException) ex, request, response, - handler); + return handleMethodArgumentNotValidException( + (MethodArgumentNotValidException) ex, request, response, handler); } else if (ex instanceof MissingServletRequestPartException) { - return handleMissingServletRequestPartException((MissingServletRequestPartException) ex, request, - response, handler); + return handleMissingServletRequestPartException( + (MissingServletRequestPartException) ex, request, response, handler); } else if (ex instanceof BindException) { return handleBindException((BindException) ex, request, response, handler); } else if (ex instanceof NoHandlerFoundException) { - return handleNoHandlerFoundException((NoHandlerFoundException) ex, request, response, handler); + return handleNoHandlerFoundException( + (NoHandlerFoundException) ex, request, response, handler); } else if (ex instanceof AsyncRequestTimeoutException) { return handleAsyncRequestTimeoutException( @@ -167,7 +173,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes } catch (Exception handlerException) { if (logger.isWarnEnabled()) { - logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception", handlerException); + logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in exception", handlerException); } } return null; @@ -507,7 +513,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes return new ModelAndView(); } - /** * Invoked to send a server error. Sets the status to 500 and also sets the * request attribute "javax.servlet.error.exception" to the Exception. @@ -515,7 +520,6 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes protected void sendServerError(Exception ex, HttpServletRequest request, HttpServletResponse response) throws IOException { - request.setAttribute("javax.servlet.error.exception", ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }