diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java index 7849bf94243..e119138b4fd 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java @@ -649,7 +649,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov } 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()); } diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java index 4271b9b0fd7..0fdd27c4691 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java @@ -516,7 +516,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { if (endIndex != -1) { String prefix = propertyPath.substring(0, startIndex); 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. strippedPaths.add(nestedPath + prefix + suffix); // Search for further keys to strip, with the first key stripped. diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java b/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java index 7f48818ee38..1b672d8f30a 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java @@ -98,8 +98,8 @@ public class TaskExecutorFactoryBean implements int maxPoolSize; int separatorIndex = this.poolSize.indexOf('-'); if (separatorIndex != -1) { - corePoolSize = Integer.valueOf(this.poolSize.substring(0, separatorIndex)); - maxPoolSize = Integer.valueOf(this.poolSize.substring(separatorIndex + 1, this.poolSize.length())); + corePoolSize = Integer.parseInt(this.poolSize.substring(0, separatorIndex)); + maxPoolSize = Integer.parseInt(this.poolSize.substring(separatorIndex + 1)); if (corePoolSize > maxPoolSize) { throw new IllegalArgumentException( "Lower bound of pool-size range must not exceed the upper bound"); diff --git a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java index f5eecbabf05..7df94778990 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -260,7 +260,7 @@ public abstract class MimeTypeUtils { throw new InvalidMimeTypeException(mimeType, "does not contain subtype after '/'"); } 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)) { throw new InvalidMimeTypeException(mimeType, "wildcard type is legal only in '*/*' (all mime types)"); } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java index 28f9f421acd..79ee3bd253e 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java @@ -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"); * you may not use this file except in compliance with the License. @@ -306,7 +306,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe int separatorIndex = concurrency.indexOf('-'); if (separatorIndex != -1) { setConcurrentConsumers(Integer.parseInt(concurrency.substring(0, separatorIndex))); - setMaxConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1, concurrency.length()))); + setMaxConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1))); } else { setConcurrentConsumers(1); @@ -380,8 +380,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe public void setMaxConcurrentConsumers(int maxConcurrentConsumers) { Assert.isTrue(maxConcurrentConsumers > 0, "'maxConcurrentConsumers' value must be at least 1 (one)"); synchronized (this.lifecycleMonitor) { - this.maxConcurrentConsumers = - (maxConcurrentConsumers > this.concurrentConsumers ? maxConcurrentConsumers : this.concurrentConsumers); + this.maxConcurrentConsumers = Math.max(maxConcurrentConsumers, this.concurrentConsumers); } } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java index f45e23387a8..2ff4d961c6d 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java @@ -104,7 +104,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta try { int separatorIndex = concurrency.indexOf('-'); if (separatorIndex != -1) { - setConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1, concurrency.length()))); + setConcurrentConsumers(Integer.parseInt(concurrency.substring(separatorIndex + 1))); } else { setConcurrentConsumers(Integer.parseInt(concurrency)); diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfig.java b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfig.java index 46870ed6d2f..cbbcbcb7fce 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfig.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsActivationSpecConfig.java @@ -201,7 +201,7 @@ public class JmsActivationSpecConfig { try { int separatorIndex = concurrency.indexOf('-'); if (separatorIndex != -1) { - setMaxConcurrency(Integer.parseInt(concurrency.substring(separatorIndex + 1, concurrency.length()))); + setMaxConcurrency(Integer.parseInt(concurrency.substring(separatorIndex + 1))); } else { setMaxConcurrency(Integer.parseInt(concurrency)); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java index ef6f2dd244d..0a16d3e37f1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java @@ -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"); * you may not use this file except in compliance with the License. @@ -254,7 +254,7 @@ public class StompDecoder { int index = inString.indexOf('\\'); while (index >= 0) { - sb.append(inString.substring(pos, index)); + sb.append(inString, pos, index); if (index + 1 >= inString.length()) { throw new StompConversionException("Illegal escape sequence at index " + index + ": " + inString); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java index 4eb5ab649c3..f67f89da5bf 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -222,7 +222,7 @@ public class StompEncoder { private StringBuilder getStringBuilder(StringBuilder sb, String inString, int i) { if (sb == null) { sb = new StringBuilder(inString.length()); - sb.append(inString.substring(0, i)); + sb.append(inString, 0, i); } return sb; } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/PatternMappingFilterProxy.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/PatternMappingFilterProxy.java index c71178a4561..ded58c13b03 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/PatternMappingFilterProxy.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/PatternMappingFilterProxy.java @@ -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"); * you may not use this file except in compliance with the License. @@ -72,7 +72,7 @@ final class PatternMappingFilterProxy implements Filter { private void addUrlPattern(String urlPattern) { Assert.notNull(urlPattern, "Found null URL 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)) { this.startsWithMatches.add(""); @@ -82,7 +82,7 @@ final class PatternMappingFilterProxy implements Filter { this.exactMatches.add(urlPattern.substring(0, urlPattern.length() - 2)); } else { - if ("".equals(urlPattern)) { + if (urlPattern.isEmpty()) { urlPattern = "/"; } this.exactMatches.add(urlPattern); diff --git a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java index c71b21ad5c3..0e215e9901a 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,14 +29,19 @@ import java.util.regex.Pattern; import org.springframework.util.Assert; /** - * Represents a URI template. A URI template is a URI-like String that contains variables - * enclosed by braces ({@code {}}) which can be expanded to produce an actual URI. + * Representation of a URI template that can be expanded with URI variables via + * {@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. * - *

See {@link #expand(Map)}, {@link #expand(Object[])}, and {@link #match(String)} - * for example usages. - * - *

This class is designed to be thread-safe and reusable, allowing for any number - * of expand or match calls. + *

Note: this class uses {@link UriComponentsBuilder} + * internally to expand URI templates, and is merely a shortcut for already + * prepared URI templates. For more dynamic preparation and extra flexibility, + * e.g. around URI encoding, consider using {@code UriComponentsBuilder} or the + * higher level {@link DefaultUriBuilderFactory} which adds several encoding + * modes on top of {@code UriComponentsBuilder}. See the + * reference docs + * for further details. * * @author Arjen Poutsma * @author Juergen Hoeller @@ -219,7 +224,7 @@ public class UriTemplate implements Serializable { throw new IllegalArgumentException( "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(regex); pattern.append(')'); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java index a768045d6b8..88df588ebf9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java @@ -211,7 +211,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware { } else { if (this.context.endsWith("/")) { - url.append(this.context.substring(0, this.context.length() - 1)); + url.append(this.context, 0, this.context.length() - 1); } else { url.append(this.context); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java index cdb7be7fa1f..317369f1bf0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java @@ -58,7 +58,7 @@ import org.springframework.web.util.WebUtils; * but this behavior can be changed by overriding the * {@link #isEligibleProperty(String, Object)} method. * - *

A URL for this view is supposed to be a HTTP redirect URL, i.e. + *

A URL for this view is supposed to be an HTTP redirect URL, i.e. * 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 * back an HTTP 303 code - if the HTTP 1.0 compatibility flag is off. @@ -389,7 +389,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { if (value == null) { 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)); endLastMatch = matcher.end(); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java index 1d4847a0d86..929446f69d7 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/WebSocketExtension.java @@ -164,7 +164,7 @@ public class WebSocketExtension { int eqIndex = parameter.indexOf('='); if (eqIndex != -1) { String attribute = parameter.substring(0, eqIndex); - String value = parameter.substring(eqIndex + 1, parameter.length()); + String value = parameter.substring(eqIndex + 1); parameters.put(attribute, value); } }