diff --git a/spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java index 8f2300c6c916e12d998e20444fb5bd83e7c2e8f3..0b0186b8a68b0c743e23061cfca9e4d97809c583 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/ResourceBundleMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -394,6 +394,8 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement @Override public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { + + // Special handling of default encoding if (format.equals("java.properties")) { String bundleName = toBundleName(baseName, locale); final String resourceName = toResourceName(bundleName, "properties"); @@ -441,6 +443,7 @@ public class ResourceBundleMessageSource extends AbstractMessageSource implement } } else { + // Delegate handling of "java.class" format to standard Control return super.newBundle(baseName, locale, format, loader, reload); } } diff --git a/spring-core/src/main/java/org/springframework/util/AlternativeJdkIdGenerator.java b/spring-core/src/main/java/org/springframework/util/AlternativeJdkIdGenerator.java index d850272eb2b2d7a934fcc925aa1ab74c805f1726..9da7e0e5ca7b0c516f2db687852e724d9bcbb904 100644 --- a/spring-core/src/main/java/org/springframework/util/AlternativeJdkIdGenerator.java +++ b/spring-core/src/main/java/org/springframework/util/AlternativeJdkIdGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -22,11 +22,10 @@ import java.util.Random; import java.util.UUID; /** - * An {@link org.springframework.util.IdGenerator IdGenerator} that uses - * {@link SecureRandom} for the initial seed and {@link Random} thereafter - * instead of calling {@link UUID#randomUUID()} every time as - * {@link org.springframework.util.JdkIdGenerator JdkIdGenerator} does. - * This provides a better balance between securely random id's and performance. + * An {@link IdGenerator} that uses {@link SecureRandom} for the initial seed and + * {@link Random} thereafter, instead of calling {@link UUID#randomUUID()} every + * time as {@link org.springframework.util.JdkIdGenerator JdkIdGenerator} does. + * This provides a better balance between securely random ids and performance. * * @author Rossen Stoyanchev * @author Rob Winch @@ -45,8 +44,8 @@ public class AlternativeJdkIdGenerator implements IdGenerator { } + @Override public UUID generateId() { - byte[] randomBytes = new byte[16]; this.random.nextBytes(randomBytes); diff --git a/spring-core/src/main/java/org/springframework/util/JdkIdGenerator.java b/spring-core/src/main/java/org/springframework/util/JdkIdGenerator.java index 6d772de9e430a2bfe2eae6f28ef3c65b6251dc88..603e5c9e86d5d76e80bd91643f73d807b7493d4e 100644 --- a/spring-core/src/main/java/org/springframework/util/JdkIdGenerator.java +++ b/spring-core/src/main/java/org/springframework/util/JdkIdGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -19,14 +19,14 @@ package org.springframework.util; import java.util.UUID; /** - * An IdGenerator that calls {@link java.util.UUID#randomUUID()}. + * An {@link IdGenerator} that calls {@link java.util.UUID#randomUUID()}. * * @author Rossen Stoyanchev - * @since 4.2 + * @since 4.1.5 */ public class JdkIdGenerator implements IdGenerator { - + @Override public UUID generateId() { return UUID.randomUUID(); } diff --git a/spring-core/src/main/java/org/springframework/util/SimpleIdGenerator.java b/spring-core/src/main/java/org/springframework/util/SimpleIdGenerator.java index 7c8b2400e591436828e87848970bef76b9392943..b7eca18507c5002f9ac589e4062e5d306f867977 100644 --- a/spring-core/src/main/java/org/springframework/util/SimpleIdGenerator.java +++ b/spring-core/src/main/java/org/springframework/util/SimpleIdGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -20,10 +20,10 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; /** - * An simple IdGenerator that starts at 1 and increments by 1 with each call. + * A simple {@link IdGenerator} that starts at 1 and increments by 1 with each call. * * @author Rossen Stoyanchev - * @since 4.2 + * @since 4.1.5 */ public class SimpleIdGenerator implements IdGenerator { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractMethodArgumentResolutionException.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractMethodArgumentResolutionException.java index d3fc2ccefd0f1a38d0586e4359c217ceb80dfbf0..df4bce8bfa01eaf96ae9de815cf036df1ced9942 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractMethodArgumentResolutionException.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractMethodArgumentResolutionException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -42,23 +42,23 @@ public abstract class AbstractMethodArgumentResolutionException extends Messagin /** * Create a new instance providing the invalid {@code MethodParameter} and - * a prepared description. Sub-classes should prepend the description with + * a prepared description. Subclasses should prepend the description with * the help of {@link #getMethodParamMessage(org.springframework.core.MethodParameter)}. */ - protected AbstractMethodArgumentResolutionException(Message message, - MethodParameter parameter, String description) { - + protected AbstractMethodArgumentResolutionException(Message message, MethodParameter param, String description) { super(message, description); - this.parameter = parameter; + this.parameter = param; } + /** * Return the MethodParameter that was rejected. */ - public MethodParameter getMethodParameter() { + public final MethodParameter getMethodParameter() { return this.parameter; } + protected static String getMethodParamMessage(MethodParameter param) { return new StringBuilder("Could not resolve method parameter at index ") .append(param.getParameterIndex()).append(" in method: ") diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentNotValidException.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentNotValidException.java index eaff0ab484c2bebfe54fd9f90987c4e4cceef186..81bd4a7e2764d98fa5b25e70b2e31f2845b83450 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentNotValidException.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentNotValidException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -49,22 +49,21 @@ public class MethodArgumentNotValidException extends AbstractMethodArgumentResol public MethodArgumentNotValidException(Message message, MethodParameter parameter, BindingResult bindingResult) { - super(message, parameter, getMethodParamMessage(parameter) + - getValidationErrorMessage(parameter, bindingResult)); - + super(message, parameter, getMethodParamMessage(parameter) + getValidationErrorMessage(bindingResult)); this.bindingResult = bindingResult; } /** - * Return the BindingResult if the failure is validation-related or {@code null}. + * Return the BindingResult if the failure is validation-related, + * or {@code null} if none. */ - public BindingResult getBindingResult() { + public final BindingResult getBindingResult() { return this.bindingResult; } - private static String getValidationErrorMessage(MethodParameter parameter, BindingResult bindingResult) { + private static String getValidationErrorMessage(BindingResult bindingResult) { if (bindingResult != null) { StringBuilder sb = new StringBuilder(); sb.append(", with ").append(bindingResult.getErrorCount()).append(" error(s): "); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentTypeMismatchException.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentTypeMismatchException.java index c4d611c99ba189a4041953785e4f38ddcea169f3..36bcd10a2ffbc3258930eea49caa6d67e22ccd63 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentTypeMismatchException.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/MethodArgumentTypeMismatchException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -29,11 +29,11 @@ import org.springframework.messaging.Message; @SuppressWarnings("serial") public class MethodArgumentTypeMismatchException extends AbstractMethodArgumentResolutionException { - /** * Create a new instance with the invalid {@code MethodParameter}. */ - public MethodArgumentTypeMismatchException(Message message, MethodParameter parameter, String description) { - super(message, parameter, getMethodParamMessage(parameter) + description); + public MethodArgumentTypeMismatchException(Message message, MethodParameter param, String description) { + super(message, param, getMethodParamMessage(param) + description); } + } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolver.java index 76a29abea1028f65714176f746f4b25af546c50c..28d6b45c16406560141930be4f029bd161c07d2f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -20,8 +20,8 @@ import org.springframework.core.MethodParameter; import org.springframework.messaging.Message; /** - * Strategy interface for resolving method parameters into argument values in - * the context of a given {@link Message}. + * Strategy interface for resolving method parameters into argument values + * in the context of a given {@link Message}. * * @author Rossen Stoyanchev * @since 4.0 @@ -39,12 +39,12 @@ public interface HandlerMethodArgumentResolver { /** * Resolves a method parameter into an argument value from a given message. - * @param parameter the method parameter to resolve. This parameter must - * have previously been passed to + * @param parameter the method parameter to resolve. + * This parameter must have previously been passed to * {@link #supportsParameter(org.springframework.core.MethodParameter)} - * and it must have returned {@code true} + * which must have returned {@code true}. * @param message the currently processed message - * @return the resolved argument value, or {@code null}. + * @return the resolved argument value, or {@code null} * @throws Exception in case of errors with the preparation of argument values */ Object resolveArgument(MethodParameter parameter, Message message) throws Exception; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java index 41d397aec879ca49a04ce08b834025ff67c3aefe..6c4a94b7e6a5719d0816a05378b076f15c205edb 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -68,7 +68,6 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { /** * Configure a custom SubscriptionRegistry to use for storing subscriptions. - * *

Note that when a custom PathMatcher is configured via * {@link #setPathMatcher}, if the custom registry is not an instance of * {@link DefaultSubscriptionRegistry}, the provided PathMatcher is not used @@ -102,9 +101,8 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { } /** - * Configure a {@link MessageHeaderInitializer} to apply to the headers of all - * messages sent to the client outbound channel. - * + * Configure a {@link MessageHeaderInitializer} to apply to the headers + * of all messages sent to the client outbound channel. *

By default this property is not set. */ public void setHeaderInitializer(MessageHeaderInitializer headerInitializer) { @@ -112,7 +110,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { } /** - * @return the configured header initializer. + * Return the configured header initializer. */ public MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; @@ -131,7 +129,6 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { @Override protected void handleMessageInternal(Message message) { - MessageHeaders headers = message.getHeaders(); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(headers); String destination = SimpMessageHeaderAccessor.getDestination(headers); @@ -197,7 +194,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { protected void sendMessageToSubscribers(String destination, Message message) { MultiValueMap subscriptions = this.subscriptionRegistry.findSubscriptions(message); - if ((subscriptions.size() > 0) && logger.isDebugEnabled()) { + if (!subscriptions.isEmpty() && logger.isDebugEnabled()) { logger.debug("Broadcasting to " + subscriptions.size() + " sessions."); } for (String sessionId : subscriptions.keySet()) { diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java index c48947a3034d6b31aa9a9ab799e117f2cc81a5cd..25100fe890aee16cb2f018f83f17df7635908e48 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java @@ -232,7 +232,7 @@ public class Jackson2ObjectMapperBuilder { * @see com.fasterxml.jackson.databind.ObjectMapper#addMixInAnnotations(Class, Class) */ public Jackson2ObjectMapperBuilder mixIn(Class target, Class mixinSource) { - if (mixIns != null) { + if (mixinSource != null) { this.mixIns.put(target, mixinSource); } return this; diff --git a/spring-web/src/main/java/org/springframework/web/client/MessageBodyClientHttpResponseWrapper.java b/spring-web/src/main/java/org/springframework/web/client/MessageBodyClientHttpResponseWrapper.java index 41ace28bbd15c37019518c451387b8562ad5dc6d..b36e37d885e52ee200ff9c75c259bc30e46f6c45 100644 --- a/spring-web/src/main/java/org/springframework/web/client/MessageBodyClientHttpResponseWrapper.java +++ b/spring-web/src/main/java/org/springframework/web/client/MessageBodyClientHttpResponseWrapper.java @@ -1,3 +1,19 @@ +/* + * Copyright 2002-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.web.client; import java.io.IOException; @@ -9,32 +25,33 @@ import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; /** - * Implementation of {@link ClientHttpResponse} that can not only check if the response - * has a message body, but also if its length is 0 (i.e. empty) by actually reading the input stream. + * Implementation of {@link ClientHttpResponse} that can not only check if + * the response has a message body, but also if its length is 0 (i.e. empty) + * by actually reading the input stream. * * @author Brian Clozel - * @since 4.1 + * @since 4.1.5 * @see rfc7230 Section 3.3.3 */ class MessageBodyClientHttpResponseWrapper implements ClientHttpResponse { + private final ClientHttpResponse response; + private PushbackInputStream pushbackInputStream; - private final ClientHttpResponse response; public MessageBodyClientHttpResponseWrapper(ClientHttpResponse response) throws IOException { this.response = response; } + /** * Indicates whether the response has a message body. - * *

Implementation returns {@code false} for: *

- * * @return {@code true} if the response has a message body, {@code false} otherwise * @throws IOException in case of I/O errors */ @@ -52,13 +69,11 @@ class MessageBodyClientHttpResponseWrapper implements ClientHttpResponse { /** * Indicates whether the response has an empty message body. - * *

Implementation tries to read the first bytes of the response stream: *

- * * @return {@code true} if the response has a zero-length message body, {@code false} otherwise * @throws IOException in case of I/O errors */ @@ -79,44 +94,46 @@ class MessageBodyClientHttpResponseWrapper implements ClientHttpResponse { } else { this.pushbackInputStream = new PushbackInputStream(body); - int b = pushbackInputStream.read(); + int b = this.pushbackInputStream.read(); if (b == -1) { return true; } else { - pushbackInputStream.unread(b); + this.pushbackInputStream.unread(b); return false; } } } + @Override - public HttpStatus getStatusCode() throws IOException { - return response.getStatusCode(); + public HttpHeaders getHeaders() { + return this.response.getHeaders(); } @Override - public int getRawStatusCode() throws IOException { - return response.getRawStatusCode(); + public InputStream getBody() throws IOException { + return (this.pushbackInputStream != null ? this.pushbackInputStream : this.response.getBody()); } @Override - public String getStatusText() throws IOException { - return response.getStatusText(); + public HttpStatus getStatusCode() throws IOException { + return this.response.getStatusCode(); } @Override - public void close() { - response.close(); + public int getRawStatusCode() throws IOException { + return this.response.getRawStatusCode(); } @Override - public InputStream getBody() throws IOException { - return this.pushbackInputStream != null ? this.pushbackInputStream : response.getBody(); + public String getStatusText() throws IOException { + return this.response.getStatusText(); } @Override - public HttpHeaders getHeaders() { - return response.getHeaders(); + public void close() { + this.response.close(); } + } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdviceChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdviceChain.java index 527deee79db58e9f6f07cbc0c6b12e3b55d17ebe..4b17fce7a1f085d89ef132f7317afec6059631bb 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdviceChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdviceChain.java @@ -18,9 +18,6 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.core.MethodParameter; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; @@ -37,8 +34,6 @@ import org.springframework.web.method.ControllerAdviceBean; */ class ResponseBodyAdviceChain { - private static final Log logger = LogFactory.getLog(ResponseBodyAdviceChain.class); - private final List advice;