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);

0 commit comments

Comments
 (0)