Deprecate StringUtils::trimWhitespace and variants
This commits deprecates - StringUtils::trimWhitespace in favor of String::strip - StringUtils::trimLeadingWhitespace in favor of String::stripLeading - StringUtils::trimTrailingWhitespace in favor of String::stripTrailing Closes gh-27769
This commit is contained in:
parent
982ba0e86d
commit
81af7330f6
|
@ -261,7 +261,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||||
public void setArgumentNamesFromStringArray(String... args) {
|
public void setArgumentNamesFromStringArray(String... args) {
|
||||||
this.argumentNames = new String[args.length];
|
this.argumentNames = new String[args.length];
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
this.argumentNames[i] = StringUtils.trimWhitespace(args[i]);
|
this.argumentNames[i] = args[i].strip();
|
||||||
if (!isVariableName(this.argumentNames[i])) {
|
if (!isVariableName(this.argumentNames[i])) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"'argumentNames' property of AbstractAspectJAdvice contains an argument name '" +
|
"'argumentNames' property of AbstractAspectJAdvice contains an argument name '" +
|
||||||
|
|
|
@ -486,7 +486,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||||
}
|
}
|
||||||
String[] tokens = StringUtils.tokenizeToStringArray(argsSpec, ",");
|
String[] tokens = StringUtils.tokenizeToStringArray(argsSpec, ",");
|
||||||
for (int i = 0; i < tokens.length; i++) {
|
for (int i = 0; i < tokens.length; i++) {
|
||||||
tokens[i] = StringUtils.trimWhitespace(tokens[i]);
|
tokens[i] = tokens[i].strip();
|
||||||
String varName = maybeExtractVariableName(tokens[i]);
|
String varName = maybeExtractVariableName(tokens[i]);
|
||||||
if (varName != null) {
|
if (varName != null) {
|
||||||
varNames.add(varName);
|
varNames.add(varName);
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.PatternMatchUtils;
|
import org.springframework.util.PatternMatchUtils;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto proxy creator that identifies beans to proxy via a list of names.
|
* Auto proxy creator that identifies beans to proxy via a list of names.
|
||||||
|
@ -69,7 +68,7 @@ public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator {
|
||||||
Assert.notEmpty(beanNames, "'beanNames' must not be empty");
|
Assert.notEmpty(beanNames, "'beanNames' must not be empty");
|
||||||
this.beanNames = new ArrayList<>(beanNames.length);
|
this.beanNames = new ArrayList<>(beanNames.length);
|
||||||
for (String mappedName : beanNames) {
|
for (String mappedName : beanNames) {
|
||||||
this.beanNames.add(StringUtils.trimWhitespace(mappedName));
|
this.beanNames.add(mappedName.strip());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base regular expression pointcut bean. JavaBean properties are:
|
* Abstract base regular expression pointcut bean. JavaBean properties are:
|
||||||
|
@ -81,7 +80,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
||||||
Assert.notEmpty(patterns, "'patterns' must not be empty");
|
Assert.notEmpty(patterns, "'patterns' must not be empty");
|
||||||
this.patterns = new String[patterns.length];
|
this.patterns = new String[patterns.length];
|
||||||
for (int i = 0; i < patterns.length; i++) {
|
for (int i = 0; i < patterns.length; i++) {
|
||||||
this.patterns[i] = StringUtils.trimWhitespace(patterns[i]);
|
this.patterns[i] = patterns[i].strip();
|
||||||
}
|
}
|
||||||
initPatternRepresentation(this.patterns);
|
initPatternRepresentation(this.patterns);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +110,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
||||||
Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty");
|
Assert.notEmpty(excludedPatterns, "'excludedPatterns' must not be empty");
|
||||||
this.excludedPatterns = new String[excludedPatterns.length];
|
this.excludedPatterns = new String[excludedPatterns.length];
|
||||||
for (int i = 0; i < excludedPatterns.length; i++) {
|
for (int i = 0; i < excludedPatterns.length; i++) {
|
||||||
this.excludedPatterns[i] = StringUtils.trimWhitespace(excludedPatterns[i]);
|
this.excludedPatterns[i] = excludedPatterns[i].strip();
|
||||||
}
|
}
|
||||||
initExcludedPatternRepresentation(this.excludedPatterns);
|
initExcludedPatternRepresentation(this.excludedPatterns);
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,31 +428,31 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
|
||||||
int beginIndex = prefixWithSep.length();
|
int beginIndex = prefixWithSep.length();
|
||||||
|
|
||||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||||
String key = StringUtils.trimWhitespace((String) entry.getKey());
|
String key = ((String) entry.getKey()).strip();
|
||||||
if (key.startsWith(prefixWithSep)) {
|
if (key.startsWith(prefixWithSep)) {
|
||||||
String property = key.substring(beginIndex);
|
String property = key.substring(beginIndex);
|
||||||
if (CLASS_KEY.equals(property)) {
|
if (CLASS_KEY.equals(property)) {
|
||||||
className = StringUtils.trimWhitespace((String) entry.getValue());
|
className = ((String) entry.getValue()).strip();
|
||||||
}
|
}
|
||||||
else if (PARENT_KEY.equals(property)) {
|
else if (PARENT_KEY.equals(property)) {
|
||||||
parent = StringUtils.trimWhitespace((String) entry.getValue());
|
parent = ((String) entry.getValue()).strip();
|
||||||
}
|
}
|
||||||
else if (ABSTRACT_KEY.equals(property)) {
|
else if (ABSTRACT_KEY.equals(property)) {
|
||||||
String val = StringUtils.trimWhitespace((String) entry.getValue());
|
String val = ((String) entry.getValue()).strip();
|
||||||
isAbstract = TRUE_VALUE.equals(val);
|
isAbstract = TRUE_VALUE.equals(val);
|
||||||
}
|
}
|
||||||
else if (SCOPE_KEY.equals(property)) {
|
else if (SCOPE_KEY.equals(property)) {
|
||||||
// Spring 2.0 style
|
// Spring 2.0 style
|
||||||
scope = StringUtils.trimWhitespace((String) entry.getValue());
|
scope = ((String) entry.getValue()).strip();
|
||||||
}
|
}
|
||||||
else if (SINGLETON_KEY.equals(property)) {
|
else if (SINGLETON_KEY.equals(property)) {
|
||||||
// Spring 1.2 style
|
// Spring 1.2 style
|
||||||
String val = StringUtils.trimWhitespace((String) entry.getValue());
|
String val = ((String) entry.getValue()).strip();
|
||||||
scope = (!StringUtils.hasLength(val) || TRUE_VALUE.equals(val) ?
|
scope = (!StringUtils.hasLength(val) || TRUE_VALUE.equals(val) ?
|
||||||
BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE);
|
BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE);
|
||||||
}
|
}
|
||||||
else if (LAZY_INIT_KEY.equals(property)) {
|
else if (LAZY_INIT_KEY.equals(property)) {
|
||||||
String val = StringUtils.trimWhitespace((String) entry.getValue());
|
String val = ((String) entry.getValue()).strip();
|
||||||
lazyInit = TRUE_VALUE.equals(val);
|
lazyInit = TRUE_VALUE.equals(val);
|
||||||
}
|
}
|
||||||
else if (property.startsWith(CONSTRUCTOR_ARG_PREFIX)) {
|
else if (property.startsWith(CONSTRUCTOR_ARG_PREFIX)) {
|
||||||
|
@ -469,7 +469,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
|
||||||
// This isn't a real property, but a reference to another prototype
|
// This isn't a real property, but a reference to another prototype
|
||||||
// Extract property name: property is of form dog(ref)
|
// Extract property name: property is of form dog(ref)
|
||||||
property = property.substring(0, property.length() - REF_SUFFIX.length());
|
property = property.substring(0, property.length() - REF_SUFFIX.length());
|
||||||
String ref = StringUtils.trimWhitespace((String) entry.getValue());
|
String ref = ((String) entry.getValue()).strip();
|
||||||
|
|
||||||
// It doesn't matter if the referenced bean hasn't yet been registered:
|
// It doesn't matter if the referenced bean hasn't yet been registered:
|
||||||
// this will ensure that the reference is resolved at runtime.
|
// this will ensure that the reference is resolved at runtime.
|
||||||
|
|
|
@ -79,8 +79,8 @@ public class SimpleConstructorNamespaceHandler implements NamespaceHandler {
|
||||||
@Override
|
@Override
|
||||||
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
|
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
|
||||||
if (node instanceof Attr attr) {
|
if (node instanceof Attr attr) {
|
||||||
String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr));
|
String argName = parserContext.getDelegate().getLocalName(attr).strip();
|
||||||
String argValue = StringUtils.trimWhitespace(attr.getValue());
|
String argValue = attr.getValue().strip();
|
||||||
|
|
||||||
ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues();
|
ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues();
|
||||||
boolean ref = false;
|
boolean ref = false;
|
||||||
|
|
|
@ -218,7 +218,9 @@ public abstract class StringUtils {
|
||||||
* @param str the {@code String} to check
|
* @param str the {@code String} to check
|
||||||
* @return the trimmed {@code String}
|
* @return the trimmed {@code String}
|
||||||
* @see java.lang.Character#isWhitespace
|
* @see java.lang.Character#isWhitespace
|
||||||
|
* @deprecated in favor of {@link String#strip()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static String trimWhitespace(String str) {
|
public static String trimWhitespace(String str) {
|
||||||
if (!hasLength(str)) {
|
if (!hasLength(str)) {
|
||||||
return str;
|
return str;
|
||||||
|
@ -255,7 +257,9 @@ public abstract class StringUtils {
|
||||||
* @param str the {@code String} to check
|
* @param str the {@code String} to check
|
||||||
* @return the trimmed {@code String}
|
* @return the trimmed {@code String}
|
||||||
* @see java.lang.Character#isWhitespace
|
* @see java.lang.Character#isWhitespace
|
||||||
|
* @deprecated in favor of {@link String#stripLeading()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static String trimLeadingWhitespace(String str) {
|
public static String trimLeadingWhitespace(String str) {
|
||||||
if (!hasLength(str)) {
|
if (!hasLength(str)) {
|
||||||
return str;
|
return str;
|
||||||
|
@ -269,7 +273,9 @@ public abstract class StringUtils {
|
||||||
* @param str the {@code String} to check
|
* @param str the {@code String} to check
|
||||||
* @return the trimmed {@code String}
|
* @return the trimmed {@code String}
|
||||||
* @see java.lang.Character#isWhitespace
|
* @see java.lang.Character#isWhitespace
|
||||||
|
* @deprecated in favor of {@link String#stripTrailing()}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static String trimTrailingWhitespace(String str) {
|
public static String trimTrailingWhitespace(String str) {
|
||||||
if (!hasLength(str)) {
|
if (!hasLength(str)) {
|
||||||
return str;
|
return str;
|
||||||
|
@ -843,7 +849,7 @@ public abstract class StringUtils {
|
||||||
// code sans the separator between the country code and the variant.
|
// code sans the separator between the country code and the variant.
|
||||||
int endIndexOfCountryCode = localeString.indexOf(country, language.length()) + country.length();
|
int endIndexOfCountryCode = localeString.indexOf(country, language.length()) + country.length();
|
||||||
// Strip off any leading '_' and whitespace, what's left is the variant.
|
// Strip off any leading '_' and whitespace, what's left is the variant.
|
||||||
variant = trimLeadingWhitespace(localeString.substring(endIndexOfCountryCode));
|
variant = localeString.substring(endIndexOfCountryCode).stripLeading();
|
||||||
if (variant.startsWith("_")) {
|
if (variant.startsWith("_")) {
|
||||||
variant = trimLeadingCharacter(variant, '_');
|
variant = trimLeadingCharacter(variant, '_');
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@ class StringUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
void trimWhitespace() {
|
void trimWhitespace() {
|
||||||
assertThat(StringUtils.trimWhitespace(null)).isEqualTo(null);
|
assertThat(StringUtils.trimWhitespace(null)).isEqualTo(null);
|
||||||
assertThat(StringUtils.trimWhitespace("")).isEqualTo("");
|
assertThat(StringUtils.trimWhitespace("")).isEqualTo("");
|
||||||
|
@ -97,6 +98,7 @@ class StringUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
void trimLeadingWhitespace() {
|
void trimLeadingWhitespace() {
|
||||||
assertThat(StringUtils.trimLeadingWhitespace(null)).isEqualTo(null);
|
assertThat(StringUtils.trimLeadingWhitespace(null)).isEqualTo(null);
|
||||||
assertThat(StringUtils.trimLeadingWhitespace("")).isEqualTo("");
|
assertThat(StringUtils.trimLeadingWhitespace("")).isEqualTo("");
|
||||||
|
@ -112,6 +114,7 @@ class StringUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
void trimTrailingWhitespace() {
|
void trimTrailingWhitespace() {
|
||||||
assertThat(StringUtils.trimTrailingWhitespace(null)).isEqualTo(null);
|
assertThat(StringUtils.trimTrailingWhitespace(null)).isEqualTo(null);
|
||||||
assertThat(StringUtils.trimTrailingWhitespace("")).isEqualTo("");
|
assertThat(StringUtils.trimTrailingWhitespace("")).isEqualTo("");
|
||||||
|
|
|
@ -145,14 +145,14 @@ class TxAdviceBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
|
||||||
private void addRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String rollbackForValue) {
|
private void addRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String rollbackForValue) {
|
||||||
String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(rollbackForValue);
|
String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(rollbackForValue);
|
||||||
for (String typeName : exceptionTypeNames) {
|
for (String typeName : exceptionTypeNames) {
|
||||||
rollbackRules.add(new RollbackRuleAttribute(StringUtils.trimWhitespace(typeName)));
|
rollbackRules.add(new RollbackRuleAttribute(typeName.strip()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNoRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String noRollbackForValue) {
|
private void addNoRollbackRuleAttributesTo(List<RollbackRuleAttribute> rollbackRules, String noRollbackForValue) {
|
||||||
String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(noRollbackForValue);
|
String[] exceptionTypeNames = StringUtils.commaDelimitedListToStringArray(noRollbackForValue);
|
||||||
for (String typeName : exceptionTypeNames) {
|
for (String typeName : exceptionTypeNames) {
|
||||||
rollbackRules.add(new NoRollbackRuleAttribute(StringUtils.trimWhitespace(typeName)));
|
rollbackRules.add(new NoRollbackRuleAttribute(typeName.strip()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class TransactionAttributeEditor extends PropertyEditorSupport {
|
||||||
RuleBasedTransactionAttribute attr = new RuleBasedTransactionAttribute();
|
RuleBasedTransactionAttribute attr = new RuleBasedTransactionAttribute();
|
||||||
for (String token : tokens) {
|
for (String token : tokens) {
|
||||||
// Trim leading and trailing whitespace.
|
// Trim leading and trailing whitespace.
|
||||||
String trimmedToken = StringUtils.trimWhitespace(token.trim());
|
String trimmedToken = token.strip();
|
||||||
// Check whether token contains illegal whitespace within text.
|
// Check whether token contains illegal whitespace within text.
|
||||||
if (StringUtils.containsWhitespace(trimmedToken)) {
|
if (StringUtils.containsWhitespace(trimmedToken)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|
Loading…
Reference in New Issue