Skip to content

Commit bcda243

Browse files
committed
Polishing
1 parent 64f304c commit bcda243

File tree

10 files changed

+59
-64
lines changed

10 files changed

+59
-64
lines changed

spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -81,11 +81,11 @@ public static void registerAspectJAnnotationAutoProxyCreatorIfNecessary(
8181

8282
private static void useClassProxyingIfNecessary(BeanDefinitionRegistry registry, Element sourceElement) {
8383
if (sourceElement != null) {
84-
boolean proxyTargetClass = Boolean.valueOf(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
84+
boolean proxyTargetClass = Boolean.parseBoolean(sourceElement.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE));
8585
if (proxyTargetClass) {
8686
AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
8787
}
88-
boolean exposeProxy = Boolean.valueOf(sourceElement.getAttribute(EXPOSE_PROXY_ATTRIBUTE));
88+
boolean exposeProxy = Boolean.parseBoolean(sourceElement.getAttribute(EXPOSE_PROXY_ATTRIBUTE));
8989
if (exposeProxy) {
9090
AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);
9191
}

spring-context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ private void setNumberHits(BitSet bits, String value, int min, int max) {
350350
if (!split[0].contains("-")) {
351351
range[1] = max - 1;
352352
}
353-
int delta = Integer.valueOf(split[1]);
353+
int delta = Integer.parseInt(split[1]);
354354
if (delta <= 0) {
355355
throw new IllegalArgumentException("Incrementer delta must be 1 or higher: '" +
356356
field + "' in expression \"" + this.expression + "\"");

spring-core/src/main/java/org/springframework/core/convert/Property.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -36,8 +36,8 @@
3636
* is not available in a number of environments (e.g. Android, Java ME), so this is
3737
* desirable for portability of Spring's core conversion facility.
3838
*
39-
* <p>Used to build a TypeDescriptor from a property location.
40-
* The built TypeDescriptor can then be used to convert from/to the property type.
39+
* <p>Used to build a {@link TypeDescriptor} from a property location. The built
40+
* {@code TypeDescriptor} can then be used to convert from/to the property type.
4141
*
4242
* @author Keith Donald
4343
* @author Phillip Webb

spring-core/src/main/java/org/springframework/util/StringUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,11 +694,11 @@ public static boolean pathEquals(String path1, String path2) {
694694
}
695695

696696
/**
697-
* Parse the given {@code localeString} value into a {@link Locale}.
697+
* Parse the given {@code String} representation into a {@link Locale}.
698698
* <p>This is the inverse operation of {@link Locale#toString Locale's toString}.
699-
* @param localeString the locale {@code String}, following {@code Locale's}
700-
* {@code toString()} format ("en", "en_UK", etc);
701-
* also accepts spaces as separators, as an alternative to underscores
699+
* @param localeString the locale {@code String}: following {@code Locale's}
700+
* {@code toString()} format ("en", "en_UK", etc), also accepting spaces as
701+
* separators (as an alternative to underscores)
702702
* @return a corresponding {@code Locale} instance, or {@code null} if none
703703
* @throws IllegalArgumentException in case of an invalid locale specification
704704
*/

spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectionHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public static Object[] setupArgumentsForVarargsInvocation(Class<?>[] requiredPar
368368
}
369369

370370

371-
static enum ArgumentsMatchKind {
371+
enum ArgumentsMatchKind {
372372

373373
/** An exact match is where the parameter types exactly match what the method/constructor is expecting */
374374
EXACT,

spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java

Lines changed: 31 additions & 28 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-2018 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.
@@ -240,8 +240,8 @@ public static UriComponentsBuilder fromUriString(String uri) {
240240
* be parsed unambiguously. Such values should be substituted for URI
241241
* variables to enable correct parsing:
242242
* <pre class="code">
243-
* String uriString = &quot;/hotels/42?filter={value}&quot;;
244-
* UriComponentsBuilder.fromUriString(uriString).buildAndExpand(&quot;hot&amp;cold&quot;);
243+
* String urlString = &quot;https://example.com/hotels/42?filter={value}&quot;;
244+
* UriComponentsBuilder.fromHttpUrl(urlString).buildAndExpand(&quot;hot&amp;cold&quot;);
245245
* </pre>
246246
* @param httpUrl the source URI
247247
* @return the URI components of the URI
@@ -373,10 +373,10 @@ public String toUriString() {
373373
}
374374

375375

376-
// URI components methods
376+
// Instance methods
377377

378378
/**
379-
* Initialize all components of this URI builder with the components of the given URI.
379+
* Initialize components of this builder from components of the given URI.
380380
* @param uri the URI
381381
* @return this UriComponentsBuilder
382382
*/
@@ -413,24 +413,28 @@ public UriComponentsBuilder uri(URI uri) {
413413
}
414414

415415
/**
416-
* Set the URI scheme. The given scheme may contain URI template variables,
417-
* and may also be {@code null} to clear the scheme of this builder.
418-
* @param scheme the URI scheme
416+
* Set or append individual URI components of this builder from the values
417+
* of the given {@link UriComponents} instance.
418+
* <p>For the semantics of each component (i.e. set vs append) check the
419+
* builder methods on this class. For example {@link #host(String)} sets
420+
* while {@link #path(String)} appends.
421+
* @param uriComponents the UriComponents to copy from
419422
* @return this UriComponentsBuilder
420423
*/
421-
public UriComponentsBuilder scheme(String scheme) {
422-
this.scheme = scheme;
424+
public UriComponentsBuilder uriComponents(UriComponents uriComponents) {
425+
Assert.notNull(uriComponents, "UriComponents must not be null");
426+
uriComponents.copyToUriComponentsBuilder(this);
423427
return this;
424428
}
425429

426430
/**
427-
* Set all components of this URI builder from the given {@link UriComponents}.
428-
* @param uriComponents the UriComponents instance
431+
* Set the URI scheme. The given scheme may contain URI template variables,
432+
* and may also be {@code null} to clear the scheme of this builder.
433+
* @param scheme the URI scheme
429434
* @return this UriComponentsBuilder
430435
*/
431-
public UriComponentsBuilder uriComponents(UriComponents uriComponents) {
432-
Assert.notNull(uriComponents, "UriComponents must not be null");
433-
uriComponents.copyToUriComponentsBuilder(this);
436+
public UriComponentsBuilder scheme(String scheme) {
437+
this.scheme = scheme;
434438
return this;
435439
}
436440

@@ -510,25 +514,25 @@ public UriComponentsBuilder path(String path) {
510514
}
511515

512516
/**
513-
* Set the path of this builder overriding all existing path and path segment values.
514-
* @param path the URI path; a {@code null} value results in an empty path.
517+
* Append path segments to the existing path. Each path segment may contain
518+
* URI template variables and should not contain any slashes.
519+
* Use {@code path("/")} subsequently to ensure a trailing slash.
520+
* @param pathSegments the URI path segments
515521
* @return this UriComponentsBuilder
516522
*/
517-
public UriComponentsBuilder replacePath(String path) {
518-
this.pathBuilder = new CompositePathComponentBuilder(path);
523+
public UriComponentsBuilder pathSegment(String... pathSegments) throws IllegalArgumentException {
524+
this.pathBuilder.addPathSegments(pathSegments);
519525
resetSchemeSpecificPart();
520526
return this;
521527
}
522528

523529
/**
524-
* Append path segments to the existing path. Each path segment may contain
525-
* URI template variables and should not contain any slashes.
526-
* Use {@code path("/")} subsequently to ensure a trailing slash.
527-
* @param pathSegments the URI path segments
530+
* Set the path of this builder overriding all existing path and path segment values.
531+
* @param path the URI path (a {@code null} value results in an empty path)
528532
* @return this UriComponentsBuilder
529533
*/
530-
public UriComponentsBuilder pathSegment(String... pathSegments) throws IllegalArgumentException {
531-
this.pathBuilder.addPathSegments(pathSegments);
534+
public UriComponentsBuilder replacePath(String path) {
535+
this.pathBuilder = new CompositePathComponentBuilder(path);
532536
resetSchemeSpecificPart();
533537
return this;
534538
}
@@ -582,7 +586,7 @@ public UriComponentsBuilder replaceQuery(String query) {
582586
* Append the given query parameter to the existing query parameters. The
583587
* given name or any of the values may contain URI template variables. If no
584588
* values are given, the resulting URI will contain the query parameter name
585-
* only (i.e. {@code ?foo} instead of {@code ?foo=bar}.
589+
* only (i.e. {@code ?foo} instead of {@code ?foo=bar}).
586590
* @param name the query parameter name
587591
* @param values the query parameter values
588592
* @return this UriComponentsBuilder
@@ -704,7 +708,7 @@ UriComponentsBuilder adaptFromForwardedHeaders(HttpHeaders headers) {
704708
}
705709
}
706710

707-
if ((this.scheme != null) && ((this.scheme.equals("http") && "80".equals(this.port)) ||
711+
if (this.scheme != null && ((this.scheme.equals("http") && "80".equals(this.port)) ||
708712
(this.scheme.equals("https") && "443".equals(this.port)))) {
709713
port(null);
710714
}
@@ -740,7 +744,6 @@ private void resetSchemeSpecificPart() {
740744
/**
741745
* Public declaration of Object's {@code clone()} method.
742746
* Delegates to {@link #cloneBuilder()}.
743-
* @see Object#clone()
744747
*/
745748
@Override
746749
public Object clone() {

spring-web/src/test/java/org/springframework/web/util/UriComponentsBuilderTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void fromUriString() {
185185
}
186186

187187
@Test // SPR-9832
188-
public void fromUriStringQueryParamWithReservedCharInValue() throws URISyntaxException {
188+
public void fromUriStringQueryParamWithReservedCharInValue() {
189189
String uri = "http://www.google.com/ig/calculator?q=1USD=?EUR";
190190
UriComponents result = UriComponentsBuilder.fromUriString(uri).build();
191191

@@ -494,7 +494,7 @@ public void fromHttpRequestWithTrailingSlash() {
494494
}
495495

496496
@Test
497-
public void path() throws URISyntaxException {
497+
public void path() {
498498
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");
499499
UriComponents result = builder.build();
500500

@@ -503,7 +503,7 @@ public void path() throws URISyntaxException {
503503
}
504504

505505
@Test
506-
public void pathSegments() throws URISyntaxException {
506+
public void pathSegments() {
507507
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
508508
UriComponents result = builder.pathSegment("foo").pathSegment("bar").build();
509509

@@ -593,7 +593,7 @@ public void replaceQuery() {
593593
}
594594

595595
@Test
596-
public void queryParams() throws URISyntaxException {
596+
public void queryParams() {
597597
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
598598
UriComponents result = builder.queryParam("baz", "qux", 42).build();
599599

@@ -605,7 +605,7 @@ public void queryParams() throws URISyntaxException {
605605
}
606606

607607
@Test
608-
public void emptyQueryParam() throws URISyntaxException {
608+
public void emptyQueryParam() {
609609
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
610610
UriComponents result = builder.queryParam("baz").build();
611611

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public BeanDefinition parse(Element element, ParserContext parserContext) {
7575

7676
HttpStatus statusCode = null;
7777
if (element.hasAttribute("status-code")) {
78-
int statusValue = Integer.valueOf(element.getAttribute("status-code"));
78+
int statusValue = Integer.parseInt(element.getAttribute("status-code"));
7979
statusCode = HttpStatus.valueOf(statusValue);
8080
}
8181

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ protected Resource getResource(String resourcePath, Resource location) throws IO
183183
return resource;
184184
}
185185
else if (logger.isTraceEnabled()) {
186-
logger.trace("Resource path=\"" + resourcePath + "\" was successfully resolved " +
187-
"but resource=\"" + resource.getURL() + "\" is neither under the " +
188-
"current location=\"" + location.getURL() + "\" nor under any of the " +
189-
"allowed locations=" + Arrays.asList(getAllowedLocations()));
186+
Resource[] allowedLocations = getAllowedLocations();
187+
logger.trace("Resource path \"" + resourcePath + "\" was successfully resolved " +
188+
"but resource \"" + resource.getURL() + "\" is neither under the " +
189+
"current location \"" + location.getURL() + "\" nor under any of the " +
190+
"allowed locations " + (allowedLocations != null ? Arrays.asList(allowedLocations) : "[]"));
190191
}
191192
}
192193
return null;
@@ -287,7 +288,7 @@ private boolean isInvalidEncodedPath(String resourcePath) {
287288
String decodedPath = URLDecoder.decode(resourcePath, "UTF-8");
288289
if (decodedPath.contains("../") || decodedPath.contains("..\\")) {
289290
if (logger.isTraceEnabled()) {
290-
logger.trace("Ignoring invalid resource path with escape sequences [" + resourcePath + "]");
291+
logger.trace("Resolved resource path contains encoded \"../\" or \"..\\\": " + resourcePath);
291292
}
292293
return true;
293294
}

spring-webmvc/src/test/java/org/springframework/web/servlet/support/ServletUriComponentsBuilderTests.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -16,19 +16,15 @@
1616

1717
package org.springframework.web.servlet.support;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNull;
21-
2219
import org.junit.Before;
2320
import org.junit.Test;
2421

25-
import org.springframework.http.HttpRequest;
26-
import org.springframework.http.server.ServletServerHttpRequest;
2722
import org.springframework.mock.web.test.MockHttpServletRequest;
2823
import org.springframework.web.context.request.RequestContextHolder;
2924
import org.springframework.web.context.request.ServletRequestAttributes;
3025
import org.springframework.web.util.UriComponents;
31-
import org.springframework.web.util.UriComponentsBuilder;
26+
27+
import static org.junit.Assert.*;
3228

3329
/**
3430
* Unit tests for
@@ -94,10 +90,7 @@ public void fromRequestWithForwardedHostAndPort() {
9490
request.addHeader("X-Forwarded-Proto", "https");
9591
request.addHeader("X-Forwarded-Host", "84.198.58.199");
9692
request.addHeader("X-Forwarded-Port", "443");
97-
98-
HttpRequest httpRequest = new ServletServerHttpRequest(request);
99-
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
100-
93+
UriComponents result = ServletUriComponentsBuilder.fromRequest(request).build();
10194
assertEquals("https://84.198.58.199/mvc-showcase", result.toString());
10295
}
10396

@@ -114,7 +107,6 @@ public void fromRequestWithForwardedPrefix() {
114107
this.request.setRequestURI("/bar");
115108
this.request.addHeader("X-Forwarded-Prefix", "/foo");
116109
UriComponents result = ServletUriComponentsBuilder.fromRequest(this.request).build();
117-
118110
assertEquals("http://localhost/foo/bar", result.toUriString());
119111
}
120112

@@ -123,7 +115,6 @@ public void fromRequestWithForwardedPrefixTrailingSlash() {
123115
this.request.setRequestURI("/bar");
124116
this.request.addHeader("X-Forwarded-Prefix", "/foo/");
125117
UriComponents result = ServletUriComponentsBuilder.fromRequest(this.request).build();
126-
127118
assertEquals("http://localhost/foo/bar", result.toUriString());
128119
}
129120

0 commit comments

Comments
 (0)