diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java index 5138aa1c3c..3404ebdb99 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java @@ -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. @@ -255,7 +255,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; } @@ -569,8 +569,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, diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java index d3390c0095..54b3cd1326 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java @@ -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 { } @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 { } @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 { + @Test(expected = IllegalArgumentException.class) + 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"); } diff --git a/spring-core/src/test/java/org/springframework/core/io/ResourceEditorTests.java b/spring-core/src/test/java/org/springframework/core/io/ResourceEditorTests.java index a5687c335d..68010cfce5 100644 --- a/spring-core/src/test/java/org/springframework/core/io/ResourceEditorTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/ResourceEditorTests.java @@ -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. @@ -31,10 +31,10 @@ import static org.junit.Assert.*; * @author Arjen Poutsma * @author Dave Syer */ -public final class ResourceEditorTests { +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 final 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()); @@ -75,14 +75,12 @@ public final class ResourceEditorTests { } } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testStrictSystemPropertyReplacement() { PropertyEditor editor = new ResourceEditor(new DefaultResourceLoader(), new StandardEnvironment(), false); 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"); diff --git a/spring-core/src/test/java/org/springframework/core/io/support/ResourceArrayPropertyEditorTests.java b/spring-core/src/test/java/org/springframework/core/io/support/ResourceArrayPropertyEditorTests.java index b75a6da128..38552bd5c0 100644 --- a/spring-core/src/test/java/org/springframework/core/io/support/ResourceArrayPropertyEditorTests.java +++ b/spring-core/src/test/java/org/springframework/core/io/support/ResourceArrayPropertyEditorTests.java @@ -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.*; 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 { } @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 @@ -67,7 +67,7 @@ public class ResourceArrayPropertyEditorTests { } } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testStrictSystemPropertyReplacement() { PropertyEditor editor = new ResourceArrayPropertyEditor( new PathMatchingResourcePatternResolver(), new StandardEnvironment(), @@ -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"); diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index 04b4ac8919..60a355768c 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -266,8 +266,8 @@ public class FormHttpMessageConverter implements HttpMessageConverter values : map.values()) { + for (Object value : values) { if (value != null && !(value instanceof String)) { return true; } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java index e98466b4e2..6099f78986 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -54,7 +54,7 @@ public class DeferredResult { private static final Log logger = LogFactory.getLog(DeferredResult.class); - private final Long timeout; + private final Long timeoutValue; private final Object timeoutResult; @@ -77,25 +77,25 @@ public class DeferredResult { } /** - * Create a DeferredResult with a timeout value. + * Create a DeferredResult with a custom timeout value. *

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(Long timeout, Object timeoutResult) { + public DeferredResult(Long timeoutValue, Object timeoutResult) { + this.timeoutValue = timeoutValue; this.timeoutResult = timeoutResult; - this.timeout = timeout; } @@ -134,7 +134,7 @@ public class DeferredResult { * Return the configured timeout value in milliseconds. */ final Long getTimeoutValue() { - return this.timeout; + return this.timeoutValue; } /** diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java index f98354b0e7..2714ff132d 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java @@ -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. @@ -67,15 +67,15 @@ import org.springframework.web.util.WebUtils; */ public abstract class AbstractSockJsService implements SockJsService, CorsConfigurationSource { - private static final Charset UTF8_CHARSET = Charset.forName("UTF-8"); + private static final String XFRAME_OPTIONS_HEADER = "X-Frame-Options"; private static final long ONE_YEAR = TimeUnit.DAYS.toSeconds(365); + private static final Charset UTF8_CHARSET = Charset.forName("UTF-8"); + + private static final Random random = new Random(); - private static final String XFRAME_OPTIONS_HEADER = "X-Frame-Options"; - - protected final Log logger = LogFactory.getLog(getClass()); private final TaskScheduler taskScheduler; @@ -88,9 +88,9 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig private boolean sessionCookieNeeded = true; - private long heartbeatTime = 25 * 1000; + private long heartbeatTime = TimeUnit.SECONDS.toMillis(25); - private long disconnectDelay = 5 * 1000; + private long disconnectDelay = TimeUnit.SECONDS.toMillis(5); private int httpMessageCacheSize = 100; @@ -287,8 +287,9 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig } /** + * Return if automatic addition of CORS headers has been disabled. * @since 4.1.2 - * @see #setSuppressCors(boolean) + * @see #setSuppressCors */ public boolean shouldSuppressCors() { return this.suppressCors; @@ -316,6 +317,7 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig } /** + * Return configure allowed {@code Origin} header values. * @since 4.1.2 * @see #setAllowedOrigins */ @@ -350,7 +352,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 private static final String IFRAME_CONTENT = "\n" + - "\n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n" + - "\n" + - "

Don't panic!

\n" + - "

This is a SockJS hidden iframe. It's used for cross domain magic.

\n" + - "\n" + - ""; + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + "\n" + + "

Don't panic!

\n" + + "

This is a SockJS hidden iframe. It's used for cross domain magic.

\n" + + "\n" + + ""; @Override public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {