Skip to content

Commit e0883f5

Browse files
committed
Polishing
1 parent 5900639 commit e0883f5

File tree

7 files changed

+57
-71
lines changed

7 files changed

+57
-71
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -255,7 +255,7 @@ else if (convertedValue instanceof String && !requiredType.isInstance(convertedV
255255
}
256256
}
257257
String trimmedValue = ((String) convertedValue).trim();
258-
if (requiredType.isEnum() && "".equals(trimmedValue)) {
258+
if (requiredType.isEnum() && trimmedValue.isEmpty()) {
259259
// It's an empty enum identifier: reset the enum value to null.
260260
return null;
261261
}
@@ -569,8 +569,7 @@ private Collection<?> convertToTypedCollection(
569569
return original;
570570
}
571571

572-
int i = 0;
573-
for (; it.hasNext(); i++) {
572+
for (int i = 0; it.hasNext(); i++) {
574573
Object element = it.next();
575574
String indexedPropertyName = buildIndexedPropertyName(propertyName, i);
576575
Object convertedElement = convertIfNecessary(indexedPropertyName, null, element,

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

Lines changed: 6 additions & 17 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-2019 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.
@@ -49,7 +49,7 @@ public void testResolvedMappedHandlerWithNoArgCtor() {
4949
}
5050

5151
@Test
52-
public void testNonExistentHandlerClass() throws Exception {
52+
public void testNonExistentHandlerClass() {
5353
String mappingPath = "org/springframework/beans/factory/xml/support/nonExistent.properties";
5454
try {
5555
new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
@@ -61,29 +61,18 @@ public void testNonExistentHandlerClass() throws Exception {
6161
}
6262

6363
@Test
64-
public void testResolveInvalidHandler() throws Exception {
65-
String mappingPath = "org/springframework/beans/factory/xml/support/invalid.properties";
66-
try {
67-
new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath);
68-
fail("Should not be able to map a class that doesn't implement NamespaceHandler");
69-
}
70-
catch (Throwable expected) {
71-
}
72-
}
73-
74-
@Test
75-
public void testCtorWithNullClassLoaderArgument() throws Exception {
64+
public void testCtorWithNullClassLoaderArgument() {
7665
// simply must not bail...
7766
new DefaultNamespaceHandlerResolver(null);
7867
}
7968

80-
@Test(expected=IllegalArgumentException.class)
81-
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() throws Exception {
69+
@Test(expected = IllegalArgumentException.class)
70+
public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() {
8271
new DefaultNamespaceHandlerResolver(null, null);
8372
}
8473

8574
@Test
86-
public void testCtorWithNonExistentMappingLocationArgument() throws Exception {
75+
public void testCtorWithNonExistentMappingLocationArgument() {
8776
// simply must not bail; we don't want non-existent resources to result in an Exception
8877
new DefaultNamespaceHandlerResolver(null, "738trbc bobabloobop871");
8978
}

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -31,10 +31,10 @@
3131
* @author Arjen Poutsma
3232
* @author Dave Syer
3333
*/
34-
public final class ResourceEditorTests {
34+
public class ResourceEditorTests {
3535

3636
@Test
37-
public void sunnyDay() throws Exception {
37+
public void sunnyDay() {
3838
PropertyEditor editor = new ResourceEditor();
3939
editor.setAsText("classpath:org/springframework/core/io/ResourceEditorTests.class");
4040
Resource resource = (Resource) editor.getValue();
@@ -43,19 +43,19 @@ public void sunnyDay() throws Exception {
4343
}
4444

4545
@Test(expected = IllegalArgumentException.class)
46-
public void ctorWithNullCtorArgs() throws Exception {
46+
public void ctorWithNullCtorArgs() {
4747
new ResourceEditor(null, null);
4848
}
4949

5050
@Test
51-
public void setAndGetAsTextWithNull() throws Exception {
51+
public void setAndGetAsTextWithNull() {
5252
PropertyEditor editor = new ResourceEditor();
5353
editor.setAsText(null);
5454
assertEquals("", editor.getAsText());
5555
}
5656

5757
@Test
58-
public void setAndGetAsTextWithWhitespaceResource() throws Exception {
58+
public void setAndGetAsTextWithWhitespaceResource() {
5959
PropertyEditor editor = new ResourceEditor();
6060
editor.setAsText(" ");
6161
assertEquals("", editor.getAsText());
@@ -75,14 +75,12 @@ public void testSystemPropertyReplacement() {
7575
}
7676
}
7777

78-
@Test(expected=IllegalArgumentException.class)
78+
@Test(expected = IllegalArgumentException.class)
7979
public void testStrictSystemPropertyReplacement() {
8080
PropertyEditor editor = new ResourceEditor(new DefaultResourceLoader(), new StandardEnvironment(), false);
8181
System.setProperty("test.prop", "foo");
8282
try {
8383
editor.setAsText("${test.prop}-${bar}");
84-
Resource resolved = (Resource) editor.getValue();
85-
assertEquals("foo-${bar}", resolved.getFilename());
8684
}
8785
finally {
8886
System.getProperties().remove("test.prop");

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

Lines changed: 4 additions & 6 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-2019 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.
@@ -32,7 +32,7 @@
3232
public class ResourceArrayPropertyEditorTests {
3333

3434
@Test
35-
public void testVanillaResource() throws Exception {
35+
public void testVanillaResource() {
3636
PropertyEditor editor = new ResourceArrayPropertyEditor();
3737
editor.setAsText("classpath:org/springframework/core/io/support/ResourceArrayPropertyEditor.class");
3838
Resource[] resources = (Resource[]) editor.getValue();
@@ -41,7 +41,7 @@ public void testVanillaResource() throws Exception {
4141
}
4242

4343
@Test
44-
public void testPatternResource() throws Exception {
44+
public void testPatternResource() {
4545
// N.B. this will sometimes fail if you use classpath: instead of classpath*:.
4646
// The result depends on the classpath - if test-classes are segregated from classes
4747
// and they come first on the classpath (like in Maven) then it breaks, if classes
@@ -67,16 +67,14 @@ public void testSystemPropertyReplacement() {
6767
}
6868
}
6969

70-
@Test(expected=IllegalArgumentException.class)
70+
@Test(expected = IllegalArgumentException.class)
7171
public void testStrictSystemPropertyReplacement() {
7272
PropertyEditor editor = new ResourceArrayPropertyEditor(
7373
new PathMatchingResourcePatternResolver(), new StandardEnvironment(),
7474
false);
7575
System.setProperty("test.prop", "foo");
7676
try {
7777
editor.setAsText("${test.prop}-${bar}");
78-
Resource[] resources = (Resource[]) editor.getValue();
79-
assertEquals("foo-${bar}", resources[0].getFilename());
8078
}
8179
finally {
8280
System.getProperties().remove("test.prop");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ private boolean isMultipart(MultiValueMap<String, ?> map, MediaType contentType)
266266
if (contentType != null) {
267267
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
268268
}
269-
for (String name : map.keySet()) {
270-
for (Object value : map.get(name)) {
269+
for (List<?> values : map.values()) {
270+
for (Object value : values) {
271271
if (value != null && !(value instanceof String)) {
272272
return true;
273273
}

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

Lines changed: 10 additions & 10 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-2019 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.
@@ -54,7 +54,7 @@ public class DeferredResult<T> {
5454
private static final Log logger = LogFactory.getLog(DeferredResult.class);
5555

5656

57-
private final Long timeout;
57+
private final Long timeoutValue;
5858

5959
private final Object timeoutResult;
6060

@@ -77,25 +77,25 @@ public DeferredResult() {
7777
}
7878

7979
/**
80-
* Create a DeferredResult with a timeout value.
80+
* Create a DeferredResult with a custom timeout value.
8181
* <p>By default not set in which case the default configured in the MVC
8282
* Java Config or the MVC namespace is used, or if that's not set, then the
8383
* timeout depends on the default of the underlying server.
84-
* @param timeout timeout value in milliseconds
84+
* @param timeoutValue timeout value in milliseconds
8585
*/
86-
public DeferredResult(Long timeout) {
87-
this(timeout, RESULT_NONE);
86+
public DeferredResult(Long timeoutValue) {
87+
this(timeoutValue, RESULT_NONE);
8888
}
8989

9090
/**
9191
* Create a DeferredResult with a timeout value and a default result to use
9292
* in case of timeout.
93-
* @param timeout timeout value in milliseconds (ignored if {@code null})
93+
* @param timeoutValue timeout value in milliseconds (ignored if {@code null})
9494
* @param timeoutResult the result to use
9595
*/
96-
public DeferredResult(Long timeout, Object timeoutResult) {
96+
public DeferredResult(Long timeoutValue, Object timeoutResult) {
97+
this.timeoutValue = timeoutValue;
9798
this.timeoutResult = timeoutResult;
98-
this.timeout = timeout;
9999
}
100100

101101

@@ -134,7 +134,7 @@ public Object getResult() {
134134
* Return the configured timeout value in milliseconds.
135135
*/
136136
final Long getTimeoutValue() {
137-
return this.timeout;
137+
return this.timeoutValue;
138138
}
139139

140140
/**

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -67,14 +67,14 @@
6767
*/
6868
public abstract class AbstractSockJsService implements SockJsService, CorsConfigurationSource {
6969

70-
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
70+
private static final String XFRAME_OPTIONS_HEADER = "X-Frame-Options";
7171

7272
private static final long ONE_YEAR = TimeUnit.DAYS.toSeconds(365);
7373

74-
private static final Random random = new Random();
74+
private static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
7575

76-
private static final String XFRAME_OPTIONS_HEADER = "X-Frame-Options";
7776

77+
private static final Random random = new Random();
7878

7979
protected final Log logger = LogFactory.getLog(getClass());
8080

@@ -88,9 +88,9 @@ public abstract class AbstractSockJsService implements SockJsService, CorsConfig
8888

8989
private boolean sessionCookieNeeded = true;
9090

91-
private long heartbeatTime = 25 * 1000;
91+
private long heartbeatTime = TimeUnit.SECONDS.toMillis(25);
9292

93-
private long disconnectDelay = 5 * 1000;
93+
private long disconnectDelay = TimeUnit.SECONDS.toMillis(5);
9494

9595
private int httpMessageCacheSize = 100;
9696

@@ -287,8 +287,9 @@ public void setSuppressCors(boolean suppressCors) {
287287
}
288288

289289
/**
290+
* Return if automatic addition of CORS headers has been disabled.
290291
* @since 4.1.2
291-
* @see #setSuppressCors(boolean)
292+
* @see #setSuppressCors
292293
*/
293294
public boolean shouldSuppressCors() {
294295
return this.suppressCors;
@@ -316,6 +317,7 @@ public void setAllowedOrigins(Collection<String> allowedOrigins) {
316317
}
317318

318319
/**
320+
* Return configure allowed {@code Origin} header values.
319321
* @since 4.1.2
320322
* @see #setAllowedOrigins
321323
*/
@@ -350,7 +352,7 @@ public final void handleRequest(ServerHttpRequest request, ServerHttpResponse re
350352
String requestInfo = (logger.isDebugEnabled() ? request.getMethod() + " " + request.getURI() : null);
351353

352354
try {
353-
if (sockJsPath.equals("") || sockJsPath.equals("/")) {
355+
if (sockJsPath.isEmpty() || sockJsPath.equals("/")) {
354356
if (requestInfo != null) {
355357
logger.debug("Processing transport request: " + requestInfo);
356358
}
@@ -571,21 +573,21 @@ else if (request.getMethod() == HttpMethod.OPTIONS) {
571573

572574
private static final String IFRAME_CONTENT =
573575
"<!DOCTYPE html>\n" +
574-
"<html>\n" +
575-
"<head>\n" +
576-
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n" +
577-
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
578-
" <script>\n" +
579-
" document.domain = document.domain;\n" +
580-
" _sockjs_onload = function(){SockJS.bootstrap_iframe();};\n" +
581-
" </script>\n" +
582-
" <script src=\"%s\"></script>\n" +
583-
"</head>\n" +
584-
"<body>\n" +
585-
" <h2>Don't panic!</h2>\n" +
586-
" <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>\n" +
587-
"</body>\n" +
588-
"</html>";
576+
"<html>\n" +
577+
"<head>\n" +
578+
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n" +
579+
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" +
580+
" <script>\n" +
581+
" document.domain = document.domain;\n" +
582+
" _sockjs_onload = function(){SockJS.bootstrap_iframe();};\n" +
583+
" </script>\n" +
584+
" <script src=\"%s\"></script>\n" +
585+
"</head>\n" +
586+
"<body>\n" +
587+
" <h2>Don't panic!</h2>\n" +
588+
" <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>\n" +
589+
"</body>\n" +
590+
"</html>";
589591

590592
@Override
591593
public void handle(ServerHttpRequest request, ServerHttpResponse response) throws IOException {

0 commit comments

Comments
 (0)