Skip to content

Commit 17a47b3

Browse files
committed
Refine use of substring operations
Closes gh-25445
1 parent 5e5723c commit 17a47b3

File tree

14 files changed

+36
-32
lines changed

14 files changed

+36
-32
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ private PointcutBody getPointcutBody(String[] tokens, int startIndex) {
649649
}
650650

651651
if (tokens[currentIndex].endsWith(")")) {
652-
sb.append(tokens[currentIndex].substring(0, tokens[currentIndex].length() - 1));
652+
sb.append(tokens[currentIndex], 0, tokens[currentIndex].length() - 1);
653653
return new PointcutBody(numTokensConsumed, sb.toString().trim());
654654
}
655655

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ private void addStrippedPropertyPaths(List<String> strippedPaths, String nestedP
516516
if (endIndex != -1) {
517517
String prefix = propertyPath.substring(0, startIndex);
518518
String key = propertyPath.substring(startIndex, endIndex + 1);
519-
String suffix = propertyPath.substring(endIndex + 1, propertyPath.length());
519+
String suffix = propertyPath.substring(endIndex + 1);
520520
// Strip the first key.
521521
strippedPaths.add(nestedPath + prefix + suffix);
522522
// Search for further keys to strip, with the first key stripped.

spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ private void determinePoolSizeRange() {
9898
int maxPoolSize;
9999
int separatorIndex = this.poolSize.indexOf('-');
100100
if (separatorIndex != -1) {
101-
corePoolSize = Integer.valueOf(this.poolSize.substring(0, separatorIndex));
102-
maxPoolSize = Integer.valueOf(this.poolSize.substring(separatorIndex + 1, this.poolSize.length()));
101+
corePoolSize = Integer.parseInt(this.poolSize.substring(0, separatorIndex));
102+
maxPoolSize = Integer.parseInt(this.poolSize.substring(separatorIndex + 1));
103103
if (corePoolSize > maxPoolSize) {
104104
throw new IllegalArgumentException(
105105
"Lower bound of pool-size range must not exceed the upper bound");

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

Lines changed: 2 additions & 2 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-2020 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.
@@ -260,7 +260,7 @@ public static MimeType parseMimeType(String mimeType) {
260260
throw new InvalidMimeTypeException(mimeType, "does not contain subtype after '/'");
261261
}
262262
String type = fullType.substring(0, subIndex);
263-
String subtype = fullType.substring(subIndex + 1, fullType.length());
263+
String subtype = fullType.substring(subIndex + 1);
264264
if (MimeType.WILDCARD_TYPE.equals(type) && !MimeType.WILDCARD_TYPE.equals(subtype)) {
265265
throw new InvalidMimeTypeException(mimeType, "wildcard type is legal only in '*/*' (all mime types)");
266266
}

spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.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.
@@ -306,7 +306,7 @@ public void setConcurrency(String concurrency) {
306306
int separatorIndex = concurrency.indexOf('-');
307307
if (separatorIndex != -1) {
308308
setConcurrentConsumers(Integer.parseInt(concurrency.substring(0, separatorIndex)));
309-
setMaxConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1, concurrency.length())));
309+
setMaxConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1)));
310310
}
311311
else {
312312
setConcurrentConsumers(1);
@@ -380,8 +380,7 @@ public final int getConcurrentConsumers() {
380380
public void setMaxConcurrentConsumers(int maxConcurrentConsumers) {
381381
Assert.isTrue(maxConcurrentConsumers > 0, "'maxConcurrentConsumers' value must be at least 1 (one)");
382382
synchronized (this.lifecycleMonitor) {
383-
this.maxConcurrentConsumers =
384-
(maxConcurrentConsumers > this.concurrentConsumers ? maxConcurrentConsumers : this.concurrentConsumers);
383+
this.maxConcurrentConsumers = Math.max(maxConcurrentConsumers, this.concurrentConsumers);
385384
}
386385
}
387386

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void setConcurrency(String concurrency) {
104104
try {
105105
int separatorIndex = concurrency.indexOf('-');
106106
if (separatorIndex != -1) {
107-
setConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1, concurrency.length())));
107+
setConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1)));
108108
}
109109
else {
110110
setConcurrentConsumers(Integer.parseInt(concurrency));

spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void setConcurrency(String concurrency) {
201201
try {
202202
int separatorIndex = concurrency.indexOf('-');
203203
if (separatorIndex != -1) {
204-
setMaxConcurrency(Integer.parseInt(concurrency.substring(separatorIndex + 1, concurrency.length())));
204+
setMaxConcurrency(Integer.parseInt(concurrency.substring(separatorIndex + 1)));
205205
}
206206
else {
207207
setMaxConcurrency(Integer.parseInt(concurrency));

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -254,7 +254,7 @@ private String unescape(String inString) {
254254
int index = inString.indexOf('\\');
255255

256256
while (index >= 0) {
257-
sb.append(inString.substring(pos, index));
257+
sb.append(inString, pos, index);
258258
if (index + 1 >= inString.length()) {
259259
throw new StompConversionException("Illegal escape sequence at index " + index + ": " + inString);
260260
}

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java

Lines changed: 2 additions & 2 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-2020 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.
@@ -222,7 +222,7 @@ else if (sb != null){
222222
private StringBuilder getStringBuilder(StringBuilder sb, String inString, int i) {
223223
if (sb == null) {
224224
sb = new StringBuilder(inString.length());
225-
sb.append(inString.substring(0, i));
225+
sb.append(inString, 0, i);
226226
}
227227
return sb;
228228
}

spring-test/src/main/java/org/springframework/test/web/servlet/setup/PatternMappingFilterProxy.java

Lines changed: 3 additions & 3 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.
@@ -72,7 +72,7 @@ public PatternMappingFilterProxy(Filter delegate, String... urlPatterns) {
7272
private void addUrlPattern(String urlPattern) {
7373
Assert.notNull(urlPattern, "Found null URL Pattern");
7474
if (urlPattern.startsWith(EXTENSION_MAPPING_PATTERN)) {
75-
this.endsWithMatches.add(urlPattern.substring(1, urlPattern.length()));
75+
this.endsWithMatches.add(urlPattern.substring(1));
7676
}
7777
else if (urlPattern.equals(PATH_MAPPING_PATTERN)) {
7878
this.startsWithMatches.add("");
@@ -82,7 +82,7 @@ else if (urlPattern.endsWith(PATH_MAPPING_PATTERN)) {
8282
this.exactMatches.add(urlPattern.substring(0, urlPattern.length() - 2));
8383
}
8484
else {
85-
if ("".equals(urlPattern)) {
85+
if (urlPattern.isEmpty()) {
8686
urlPattern = "/";
8787
}
8888
this.exactMatches.add(urlPattern);

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

Lines changed: 14 additions & 9 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-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.
@@ -29,14 +29,19 @@
2929
import org.springframework.util.Assert;
3030

3131
/**
32-
* Represents a URI template. A URI template is a URI-like String that contains variables
33-
* enclosed by braces ({@code {}}) which can be expanded to produce an actual URI.
32+
* Representation of a URI template that can be expanded with URI variables via
33+
* {@link #expand(Map)}, {@link #expand(Object[])}, or matched to a URL via
34+
* {@link #match(String)}. This class is designed to be thread-safe and
35+
* reusable, and allows any number of expand or match calls.
3436
*
35-
* <p>See {@link #expand(Map)}, {@link #expand(Object[])}, and {@link #match(String)}
36-
* for example usages.
37-
*
38-
* <p>This class is designed to be thread-safe and reusable, allowing for any number
39-
* of expand or match calls.
37+
* <p><strong>Note:</strong> this class uses {@link UriComponentsBuilder}
38+
* internally to expand URI templates, and is merely a shortcut for already
39+
* prepared URI templates. For more dynamic preparation and extra flexibility,
40+
* e.g. around URI encoding, consider using {@code UriComponentsBuilder} or the
41+
* higher level {@link DefaultUriBuilderFactory} which adds several encoding
42+
* modes on top of {@code UriComponentsBuilder}. See the
43+
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-uri-building">reference docs</a>
44+
* for further details.
4045
*
4146
* @author Arjen Poutsma
4247
* @author Juergen Hoeller
@@ -219,7 +224,7 @@ else if (c == '}') {
219224
throw new IllegalArgumentException(
220225
"No custom regular expression specified after ':' in \"" + variable + "\"");
221226
}
222-
String regex = variable.substring(idx + 1, variable.length());
227+
String regex = variable.substring(idx + 1);
223228
pattern.append('(');
224229
pattern.append(regex);
225230
pattern.append(')');

spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ String createUrl() throws JspException {
211211
}
212212
else {
213213
if (this.context.endsWith("/")) {
214-
url.append(this.context.substring(0, this.context.length() - 1));
214+
url.append(this.context, 0, this.context.length() - 1);
215215
}
216216
else {
217217
url.append(this.context);

spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* but this behavior can be changed by overriding the
5959
* {@link #isEligibleProperty(String, Object)} method.
6060
*
61-
* <p>A URL for this view is supposed to be a HTTP redirect URL, i.e.
61+
* <p>A URL for this view is supposed to be an HTTP redirect URL, i.e.
6262
* suitable for HttpServletResponse's {@code sendRedirect} method, which
6363
* is what actually does the redirect if the HTTP 1.0 flag is on, or via sending
6464
* back an HTTP 303 code - if the HTTP 1.0 compatibility flag is off.
@@ -389,7 +389,7 @@ protected StringBuilder replaceUriTemplateVariables(
389389
if (value == null) {
390390
throw new IllegalArgumentException("Model has no value for key '" + name + "'");
391391
}
392-
result.append(targetUrl.substring(endLastMatch, matcher.start()));
392+
result.append(targetUrl, endLastMatch, matcher.start());
393393
result.append(UriUtils.encodePathSegment(value.toString(), encodingScheme));
394394
endLastMatch = matcher.end();
395395
}

spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private static WebSocketExtension parseExtension(String extension) {
164164
int eqIndex = parameter.indexOf('=');
165165
if (eqIndex != -1) {
166166
String attribute = parameter.substring(0, eqIndex);
167-
String value = parameter.substring(eqIndex + 1, parameter.length());
167+
String value = parameter.substring(eqIndex + 1);
168168
parameters.put(attribute, value);
169169
}
170170
}

0 commit comments

Comments
 (0)