Browse Source

Polishing

pull/25598/head
Juergen Hoeller 7 years ago
parent
commit
a41a5e195f
  1. 6
      spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java
  2. 7
      spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java
  3. 21
      spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java
  4. 12
      spring-core/src/test/java/org/springframework/core/io/ResourceEditorTests.java
  5. 8
      spring-core/src/test/java/org/springframework/core/io/support/ResourceArrayPropertyEditorTests.java
  6. 4
      spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java
  7. 8
      spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java
  8. 4
      spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
  9. 21
      spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java
  10. 42
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java

6
spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@ -154,7 +154,6 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa @@ -154,7 +154,6 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
MethodInvocation invocation;
Object oldProxy = null;
boolean setProxyContext = false;
@ -207,7 +206,8 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa @@ -207,7 +206,8 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
}
else {
// We need to create a method invocation...
invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
MethodInvocation invocation =
new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
// Proceed to the joinpoint through the interceptor chain.
retVal = invocation.proceed();
}

7
spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@ -247,7 +247,7 @@ class TypeConverterDelegate { @@ -247,7 +247,7 @@ class TypeConverterDelegate {
}
}
String trimmedValue = ((String) convertedValue).trim();
if (requiredType.isEnum() && "".equals(trimmedValue)) {
if (requiredType.isEnum() && trimmedValue.isEmpty()) {
// It's an empty enum identifier: reset the enum value to null.
return null;
}
@ -559,8 +559,7 @@ class TypeConverterDelegate { @@ -559,8 +559,7 @@ class TypeConverterDelegate {
return original;
}
int i = 0;
for (; it.hasNext(); i++) {
for (int i = 0; it.hasNext(); i++) {
Object element = it.next();
String indexedPropertyName = buildIndexedPropertyName(propertyName, i);
Object convertedElement = convertIfNecessary(indexedPropertyName, null, element,

21
spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 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,7 +49,7 @@ public class DefaultNamespaceHandlerResolverTests { @@ -49,7 +49,7 @@ public class DefaultNamespaceHandlerResolverTests {
}
@Test
public void testNonExistentHandlerClass() throws Exception {
public void testNonExistentHandlerClass() {
String mappingPath = "org/springframework/beans/factory/xml/support/nonExistent.properties";
try {
new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
@ -61,29 +61,18 @@ public class DefaultNamespaceHandlerResolverTests { @@ -61,29 +61,18 @@ public class DefaultNamespaceHandlerResolverTests {
}
@Test
public void testResolveInvalidHandler() throws Exception {
String mappingPath = "org/springframework/beans/factory/xml/support/invalid.properties";
try {
new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
fail("Should not be able to map a class that doesn't implement NamespaceHandler");
}
catch (Throwable expected) {
}
}
@Test
public void testCtorWithNullClassLoaderArgument() throws Exception {
public void testCtorWithNullClassLoaderArgument() {
// simply must not bail...
new DefaultNamespaceHandlerResolver(null);
}
@Test(expected = IllegalArgumentException.class)
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() throws Exception {
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() {
new DefaultNamespaceHandlerResolver(null, null);
}
@Test
public void testCtorWithNonExistentMappingLocationArgument() throws Exception {
public void testCtorWithNonExistentMappingLocationArgument() {
// simply must not bail; we don't want non-existent resources to result in an Exception
new DefaultNamespaceHandlerResolver(null, "738trbc bobabloobop871");
}

12
spring-core/src/test/java/org/springframework/core/io/ResourceEditorTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2019 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.
@ -34,7 +34,7 @@ import static org.junit.Assert.*; @@ -34,7 +34,7 @@ import static org.junit.Assert.*;
public class ResourceEditorTests {
@Test
public void sunnyDay() throws Exception {
public void sunnyDay() {
PropertyEditor editor = new ResourceEditor();
editor.setAsText("classpath:org/springframework/core/io/ResourceEditorTests.class");
Resource resource = (Resource) editor.getValue();
@ -43,19 +43,19 @@ public class ResourceEditorTests { @@ -43,19 +43,19 @@ public class ResourceEditorTests {
}
@Test(expected = IllegalArgumentException.class)
public void ctorWithNullCtorArgs() throws Exception {
public void ctorWithNullCtorArgs() {
new ResourceEditor(null, null);
}
@Test
public void setAndGetAsTextWithNull() throws Exception {
public void setAndGetAsTextWithNull() {
PropertyEditor editor = new ResourceEditor();
editor.setAsText(null);
assertEquals("", editor.getAsText());
}
@Test
public void setAndGetAsTextWithWhitespaceResource() throws Exception {
public void setAndGetAsTextWithWhitespaceResource() {
PropertyEditor editor = new ResourceEditor();
editor.setAsText(" ");
assertEquals("", editor.getAsText());
@ -81,8 +81,6 @@ public class ResourceEditorTests { @@ -81,8 +81,6 @@ public class ResourceEditorTests {
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource resolved = (Resource) editor.getValue();
assertEquals("foo-${bar}", resolved.getFilename());
}
finally {
System.getProperties().remove("test.prop");

8
spring-core/src/test/java/org/springframework/core/io/support/ResourceArrayPropertyEditorTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2019 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.
@ -32,7 +32,7 @@ import static org.junit.Assert.*; @@ -32,7 +32,7 @@ import static org.junit.Assert.*;
public class ResourceArrayPropertyEditorTests {
@Test
public void testVanillaResource() throws Exception {
public void testVanillaResource() {
PropertyEditor editor = new ResourceArrayPropertyEditor();
editor.setAsText("classpath:org/springframework/core/io/support/ResourceArrayPropertyEditor.class");
Resource[] resources = (Resource[]) editor.getValue();
@ -41,7 +41,7 @@ public class ResourceArrayPropertyEditorTests { @@ -41,7 +41,7 @@ public class ResourceArrayPropertyEditorTests {
}
@Test
public void testPatternResource() throws Exception {
public void testPatternResource() {
// N.B. this will sometimes fail if you use classpath: instead of classpath*:.
// The result depends on the classpath - if test-classes are segregated from classes
// and they come first on the classpath (like in Maven) then it breaks, if classes
@ -75,8 +75,6 @@ public class ResourceArrayPropertyEditorTests { @@ -75,8 +75,6 @@ public class ResourceArrayPropertyEditorTests {
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource[] resources = (Resource[]) editor.getValue();
assertEquals("foo-${bar}", resources[0].getFilename());
}
finally {
System.getProperties().remove("test.prop");

4
spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@ -293,7 +293,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta @@ -293,7 +293,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
MessageConsumer consumer = createConsumer(session, destination);
if (this.taskExecutor != null) {
consumer.setMessageListener(message -> taskExecutor.execute(() -> processMessage(message, session)));
consumer.setMessageListener(message -> this.taskExecutor.execute(() -> processMessage(message, session)));
}
else {
consumer.setMessageListener(message -> processMessage(message, session));

8
spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@ -139,7 +139,7 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM @@ -139,7 +139,7 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
* @since 5.0.7
*/
public List<HttpMessageWriter<?>> getPartWriters() {
return Collections.unmodifiableList(partWriters);
return Collections.unmodifiableList(this.partWriters);
}
/**
@ -195,8 +195,8 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM @@ -195,8 +195,8 @@ public class MultipartHttpMessageWriter implements HttpMessageWriter<MultiValueM
if (contentType != null) {
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
}
for (String name : map.keySet()) {
for (Object value : map.get(name)) {
for (List<?> values : map.values()) {
for (Object value : values) {
if (value != null && !(value instanceof String)) {
return true;
}

4
spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java

@ -279,8 +279,8 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue @@ -279,8 +279,8 @@ public class FormHttpMessageConverter implements HttpMessageConverter<MultiValue
if (contentType != null) {
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
}
for (String name : map.keySet()) {
for (Object value : map.get(name)) {
for (List<?> values : map.values()) {
for (Object value : values) {
if (value != null && !(value instanceof String)) {
return true;
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@ -48,6 +48,7 @@ import org.springframework.web.context.request.NativeWebRequest; @@ -48,6 +48,7 @@ import org.springframework.web.context.request.NativeWebRequest;
* @author Juergen Hoeller
* @author Rob Winch
* @since 3.2
* @param <T> the result type
*/
public class DeferredResult<T> {
@ -57,7 +58,7 @@ public class DeferredResult<T> { @@ -57,7 +58,7 @@ public class DeferredResult<T> {
@Nullable
private final Long timeout;
private final Long timeoutValue;
private final Object timeoutResult;
@ -82,25 +83,25 @@ public class DeferredResult<T> { @@ -82,25 +83,25 @@ public class DeferredResult<T> {
}
/**
* Create a DeferredResult with a timeout value.
* Create a DeferredResult with a custom timeout value.
* <p>By default not set in which case the default configured in the MVC
* Java Config or the MVC namespace is used, or if that's not set, then the
* timeout depends on the default of the underlying server.
* @param timeout timeout value in milliseconds
* @param timeoutValue timeout value in milliseconds
*/
public DeferredResult(Long timeout) {
this(timeout, RESULT_NONE);
public DeferredResult(Long timeoutValue) {
this(timeoutValue, RESULT_NONE);
}
/**
* Create a DeferredResult with a timeout value and a default result to use
* in case of timeout.
* @param timeout timeout value in milliseconds (ignored if {@code null})
* @param timeoutValue timeout value in milliseconds (ignored if {@code null})
* @param timeoutResult the result to use
*/
public DeferredResult(@Nullable Long timeout, Object timeoutResult) {
public DeferredResult(@Nullable Long timeoutValue, Object timeoutResult) {
this.timeoutResult = timeoutResult;
this.timeout = timeout;
this.timeoutValue = timeoutValue;
}
@ -141,7 +142,7 @@ public class DeferredResult<T> { @@ -141,7 +142,7 @@ public class DeferredResult<T> {
*/
@Nullable
final Long getTimeoutValue() {
return this.timeout;
return this.timeoutValue;
}
/**

42
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,12 +68,12 @@ import org.springframework.web.util.WebUtils; @@ -68,12 +68,12 @@ import org.springframework.web.util.WebUtils;
*/
public abstract class AbstractSockJsService implements SockJsService, CorsConfigurationSource {
private static final long ONE_YEAR = TimeUnit.DAYS.toSeconds(365);
private static final String XFRAME_OPTIONS_HEADER = "X-Frame-Options";
private static final Random random = new Random();
private static final long ONE_YEAR = TimeUnit.DAYS.toSeconds(365);
private static final String XFRAME_OPTIONS_HEADER = "X-Frame-Options";
private static final Random random = new Random();
protected final Log logger = LogFactory.getLog(getClass());
@ -286,6 +286,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig @@ -286,6 +286,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
}
/**
* Return if automatic addition of CORS headers has been disabled.
* @since 4.1.2
* @see #setSuppressCors(boolean)
*/
@ -315,6 +316,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig @@ -315,6 +316,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
}
/**
* Return configure allowed {@code Origin} header values.
* @since 4.1.2
* @see #setAllowedOrigins
*/
@ -349,7 +351,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig @@ -349,7 +351,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
String requestInfo = (logger.isDebugEnabled() ? request.getMethod() + " " + request.getURI() : null);
try {
if (sockJsPath.equals("") || sockJsPath.equals("/")) {
if (sockJsPath.isEmpty() || sockJsPath.equals("/")) {
if (requestInfo != null) {
logger.debug("Processing transport request: " + requestInfo);
}
@ -571,21 +573,21 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig @@ -571,21 +573,21 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
private static final String IFRAME_CONTENT =
"<!DOCTYPE html>\n" +
"<html>\n" +
"<head>\n" +
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n" +
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
" <script>\n" +
" document.domain = document.domain;\n" +
" _sockjs_onload = function(){SockJS.bootstrap_iframe();};\n" +
" </script>\n" +
" <script src=\"%s\"></script>\n" +
"</head>\n" +
"<body>\n" +
" <h2>Don't panic!</h2>\n" +
" <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>\n" +
"</body>\n" +
"</html>";
"<html>\n" +
"<head>\n" +
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n" +
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
" <script>\n" +
" document.domain = document.domain;\n" +
" _sockjs_onload = function(){SockJS.bootstrap_iframe();};\n" +
" </script>\n" +
" <script src=\"%s\"></script>\n" +
"</head>\n" +
"<body>\n" +
" <h2>Don't panic!</h2>\n" +
" <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>\n" +
"</body>\n" +
"</html>";
@Override
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {

Loading…
Cancel
Save