Refine use of substring operations
Closes gh-25445
This commit is contained in:
@@ -648,7 +648,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tokens[currentIndex].endsWith(")")) {
|
if (tokens[currentIndex].endsWith(")")) {
|
||||||
sb.append(tokens[currentIndex].substring(0, tokens[currentIndex].length() - 1));
|
sb.append(tokens[currentIndex], 0, tokens[currentIndex].length() - 1);
|
||||||
return new PointcutBody(numTokensConsumed, sb.toString().trim());
|
return new PointcutBody(numTokensConsumed, sb.toString().trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -501,7 +501,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
|
|||||||
if (endIndex != -1) {
|
if (endIndex != -1) {
|
||||||
String prefix = propertyPath.substring(0, startIndex);
|
String prefix = propertyPath.substring(0, startIndex);
|
||||||
String key = propertyPath.substring(startIndex, endIndex + 1);
|
String key = propertyPath.substring(startIndex, endIndex + 1);
|
||||||
String suffix = propertyPath.substring(endIndex + 1, propertyPath.length());
|
String suffix = propertyPath.substring(endIndex + 1);
|
||||||
// Strip the first key.
|
// Strip the first key.
|
||||||
strippedPaths.add(nestedPath + prefix + suffix);
|
strippedPaths.add(nestedPath + prefix + suffix);
|
||||||
// Search for further keys to strip, with the first key stripped.
|
// Search for further keys to strip, with the first key stripped.
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ public class TaskExecutorFactoryBean implements
|
|||||||
int maxPoolSize;
|
int maxPoolSize;
|
||||||
int separatorIndex = this.poolSize.indexOf('-');
|
int separatorIndex = this.poolSize.indexOf('-');
|
||||||
if (separatorIndex != -1) {
|
if (separatorIndex != -1) {
|
||||||
corePoolSize = Integer.valueOf(this.poolSize.substring(0, separatorIndex));
|
corePoolSize = Integer.parseInt(this.poolSize.substring(0, separatorIndex));
|
||||||
maxPoolSize = Integer.valueOf(this.poolSize.substring(separatorIndex + 1, this.poolSize.length()));
|
maxPoolSize = Integer.parseInt(this.poolSize.substring(separatorIndex + 1));
|
||||||
if (corePoolSize > maxPoolSize) {
|
if (corePoolSize > maxPoolSize) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Lower bound of pool-size range must not exceed the upper bound");
|
"Lower bound of pool-size range must not exceed the upper bound");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -201,7 +201,7 @@ public abstract class MimeTypeUtils {
|
|||||||
throw new InvalidMimeTypeException(mimeType, "does not contain subtype after '/'");
|
throw new InvalidMimeTypeException(mimeType, "does not contain subtype after '/'");
|
||||||
}
|
}
|
||||||
String type = fullType.substring(0, subIndex);
|
String type = fullType.substring(0, subIndex);
|
||||||
String subtype = fullType.substring(subIndex + 1, fullType.length());
|
String subtype = fullType.substring(subIndex + 1);
|
||||||
if (MimeType.WILDCARD_TYPE.equals(type) && !MimeType.WILDCARD_TYPE.equals(subtype)) {
|
if (MimeType.WILDCARD_TYPE.equals(type) && !MimeType.WILDCARD_TYPE.equals(subtype)) {
|
||||||
throw new InvalidMimeTypeException(mimeType, "wildcard type is legal only in '*/*' (all mime types)");
|
throw new InvalidMimeTypeException(mimeType, "wildcard type is legal only in '*/*' (all mime types)");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -310,7 +310,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||||||
int separatorIndex = concurrency.indexOf('-');
|
int separatorIndex = concurrency.indexOf('-');
|
||||||
if (separatorIndex != -1) {
|
if (separatorIndex != -1) {
|
||||||
setConcurrentConsumers(Integer.parseInt(concurrency.substring(0, separatorIndex)));
|
setConcurrentConsumers(Integer.parseInt(concurrency.substring(0, separatorIndex)));
|
||||||
setMaxConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1, concurrency.length())));
|
setMaxConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setConcurrentConsumers(1);
|
setConcurrentConsumers(1);
|
||||||
@@ -384,8 +384,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
|||||||
public void setMaxConcurrentConsumers(int maxConcurrentConsumers) {
|
public void setMaxConcurrentConsumers(int maxConcurrentConsumers) {
|
||||||
Assert.isTrue(maxConcurrentConsumers > 0, "'maxConcurrentConsumers' value must be at least 1 (one)");
|
Assert.isTrue(maxConcurrentConsumers > 0, "'maxConcurrentConsumers' value must be at least 1 (one)");
|
||||||
synchronized (this.lifecycleMonitor) {
|
synchronized (this.lifecycleMonitor) {
|
||||||
this.maxConcurrentConsumers =
|
this.maxConcurrentConsumers = Math.max(maxConcurrentConsumers, this.concurrentConsumers);
|
||||||
(maxConcurrentConsumers > this.concurrentConsumers ? maxConcurrentConsumers : this.concurrentConsumers);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
|||||||
try {
|
try {
|
||||||
int separatorIndex = concurrency.indexOf('-');
|
int separatorIndex = concurrency.indexOf('-');
|
||||||
if (separatorIndex != -1) {
|
if (separatorIndex != -1) {
|
||||||
setConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1, concurrency.length())));
|
setConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setConcurrentConsumers(Integer.parseInt(concurrency));
|
setConcurrentConsumers(Integer.parseInt(concurrency));
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ public class JmsActivationSpecConfig {
|
|||||||
try {
|
try {
|
||||||
int separatorIndex = concurrency.indexOf('-');
|
int separatorIndex = concurrency.indexOf('-');
|
||||||
if (separatorIndex != -1) {
|
if (separatorIndex != -1) {
|
||||||
setMaxConcurrency(Integer.parseInt(concurrency.substring(separatorIndex + 1, concurrency.length())));
|
setMaxConcurrency(Integer.parseInt(concurrency.substring(separatorIndex + 1)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setMaxConcurrency(Integer.parseInt(concurrency));
|
setMaxConcurrency(Integer.parseInt(concurrency));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -263,7 +263,7 @@ public class StompDecoder {
|
|||||||
int index = inString.indexOf('\\');
|
int index = inString.indexOf('\\');
|
||||||
|
|
||||||
while (index >= 0) {
|
while (index >= 0) {
|
||||||
sb.append(inString.substring(pos, index));
|
sb.append(inString, pos, index);
|
||||||
if (index + 1 >= inString.length()) {
|
if (index + 1 >= inString.length()) {
|
||||||
throw new StompConversionException("Illegal escape sequence at index " + index + ": " + inString);
|
throw new StompConversionException("Illegal escape sequence at index " + index + ": " + inString);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -224,7 +224,7 @@ public class StompEncoder {
|
|||||||
private StringBuilder getStringBuilder(@Nullable StringBuilder sb, String inString, int i) {
|
private StringBuilder getStringBuilder(@Nullable StringBuilder sb, String inString, int i) {
|
||||||
if (sb == null) {
|
if (sb == null) {
|
||||||
sb = new StringBuilder(inString.length());
|
sb = new StringBuilder(inString.length());
|
||||||
sb.append(inString.substring(0, i));
|
sb.append(inString, 0, i);
|
||||||
}
|
}
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -73,7 +73,7 @@ final class PatternMappingFilterProxy implements Filter {
|
|||||||
private void addUrlPattern(String urlPattern) {
|
private void addUrlPattern(String urlPattern) {
|
||||||
Assert.notNull(urlPattern, "Found null URL Pattern");
|
Assert.notNull(urlPattern, "Found null URL Pattern");
|
||||||
if (urlPattern.startsWith(EXTENSION_MAPPING_PATTERN)) {
|
if (urlPattern.startsWith(EXTENSION_MAPPING_PATTERN)) {
|
||||||
this.endsWithMatches.add(urlPattern.substring(1, urlPattern.length()));
|
this.endsWithMatches.add(urlPattern.substring(1));
|
||||||
}
|
}
|
||||||
else if (urlPattern.equals(PATH_MAPPING_PATTERN)) {
|
else if (urlPattern.equals(PATH_MAPPING_PATTERN)) {
|
||||||
this.startsWithMatches.add("");
|
this.startsWithMatches.add("");
|
||||||
@@ -83,7 +83,7 @@ final class PatternMappingFilterProxy implements Filter {
|
|||||||
this.exactMatches.add(urlPattern.substring(0, urlPattern.length() - 2));
|
this.exactMatches.add(urlPattern.substring(0, urlPattern.length() - 2));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ("".equals(urlPattern)) {
|
if (urlPattern.isEmpty()) {
|
||||||
urlPattern = "/";
|
urlPattern = "/";
|
||||||
}
|
}
|
||||||
this.exactMatches.add(urlPattern);
|
this.exactMatches.add(urlPattern);
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -30,14 +30,19 @@ import org.springframework.lang.Nullable;
|
|||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a URI template. A URI template is a URI-like String that contains variables
|
* Representation of a URI template that can be expanded with URI variables via
|
||||||
* enclosed by braces ({@code {}}) which can be expanded to produce an actual URI.
|
* {@link #expand(Map)}, {@link #expand(Object[])}, or matched to a URL via
|
||||||
|
* {@link #match(String)}. This class is designed to be thread-safe and
|
||||||
|
* reusable, and allows any number of expand or match calls.
|
||||||
*
|
*
|
||||||
* <p>See {@link #expand(Map)}, {@link #expand(Object[])}, and {@link #match(String)}
|
* <p><strong>Note:</strong> this class uses {@link UriComponentsBuilder}
|
||||||
* for example usages.
|
* internally to expand URI templates, and is merely a shortcut for already
|
||||||
*
|
* prepared URI templates. For more dynamic preparation and extra flexibility,
|
||||||
* <p>This class is designed to be thread-safe and reusable, allowing for any number
|
* e.g. around URI encoding, consider using {@code UriComponentsBuilder} or the
|
||||||
* of expand or match calls.
|
* higher level {@link DefaultUriBuilderFactory} which adds several encoding
|
||||||
|
* modes on top of {@code UriComponentsBuilder}. See the
|
||||||
|
* <a href="https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-uri-building">reference docs</a>
|
||||||
|
* for further details.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
@@ -220,7 +225,7 @@ public class UriTemplate implements Serializable {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"No custom regular expression specified after ':' in \"" + variable + "\"");
|
"No custom regular expression specified after ':' in \"" + variable + "\"");
|
||||||
}
|
}
|
||||||
String regex = variable.substring(idx + 1, variable.length());
|
String regex = variable.substring(idx + 1);
|
||||||
pattern.append('(');
|
pattern.append('(');
|
||||||
pattern.append(regex);
|
pattern.append(regex);
|
||||||
pattern.append(')');
|
pattern.append(')');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -245,12 +245,12 @@ public class RedirectView extends AbstractUrlBasedView {
|
|||||||
String name = matcher.group(1);
|
String name = matcher.group(1);
|
||||||
Object value = (model.containsKey(name) ? model.get(name) : uriVariables.get(name));
|
Object value = (model.containsKey(name) ? model.get(name) : uriVariables.get(name));
|
||||||
Assert.notNull(value, () -> "No value for URI variable '" + name + "'");
|
Assert.notNull(value, () -> "No value for URI variable '" + name + "'");
|
||||||
result.append(targetUrl.substring(endLastMatch, matcher.start()));
|
result.append(targetUrl, endLastMatch, matcher.start());
|
||||||
result.append(encodeUriVariable(value.toString()));
|
result.append(encodeUriVariable(value.toString()));
|
||||||
endLastMatch = matcher.end();
|
endLastMatch = matcher.end();
|
||||||
found = matcher.find();
|
found = matcher.find();
|
||||||
}
|
}
|
||||||
result.append(targetUrl.substring(endLastMatch, targetUrl.length()));
|
result.append(targetUrl.substring(endLastMatch));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this.context.endsWith("/")) {
|
if (this.context.endsWith("/")) {
|
||||||
url.append(this.context.substring(0, this.context.length() - 1));
|
url.append(this.context, 0, this.context.length() - 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
url.append(this.context);
|
url.append(this.context);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ import org.springframework.web.util.WebUtils;
|
|||||||
* but this behavior can be changed by overriding the
|
* but this behavior can be changed by overriding the
|
||||||
* {@link #isEligibleProperty(String, Object)} method.
|
* {@link #isEligibleProperty(String, Object)} method.
|
||||||
*
|
*
|
||||||
* <p>A URL for this view is supposed to be a HTTP redirect URL, i.e.
|
* <p>A URL for this view is supposed to be an HTTP redirect URL, i.e.
|
||||||
* suitable for HttpServletResponse's {@code sendRedirect} method, which
|
* suitable for HttpServletResponse's {@code sendRedirect} method, which
|
||||||
* is what actually does the redirect if the HTTP 1.0 flag is on, or via sending
|
* is what actually does the redirect if the HTTP 1.0 flag is on, or via sending
|
||||||
* back an HTTP 303 code - if the HTTP 1.0 compatibility flag is off.
|
* back an HTTP 303 code - if the HTTP 1.0 compatibility flag is off.
|
||||||
@@ -387,7 +387,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new IllegalArgumentException("Model has no value for key '" + name + "'");
|
throw new IllegalArgumentException("Model has no value for key '" + name + "'");
|
||||||
}
|
}
|
||||||
result.append(targetUrl.substring(endLastMatch, matcher.start()));
|
result.append(targetUrl, endLastMatch, matcher.start());
|
||||||
result.append(UriUtils.encodePathSegment(value.toString(), encodingScheme));
|
result.append(UriUtils.encodePathSegment(value.toString(), encodingScheme));
|
||||||
endLastMatch = matcher.end();
|
endLastMatch = matcher.end();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ public class WebSocketExtension {
|
|||||||
int eqIndex = parameter.indexOf('=');
|
int eqIndex = parameter.indexOf('=');
|
||||||
if (eqIndex != -1) {
|
if (eqIndex != -1) {
|
||||||
String attribute = parameter.substring(0, eqIndex);
|
String attribute = parameter.substring(0, eqIndex);
|
||||||
String value = parameter.substring(eqIndex + 1, parameter.length());
|
String value = parameter.substring(eqIndex + 1);
|
||||||
parameters.put(attribute, value);
|
parameters.put(attribute, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user