Skip to content

Commit 11d4272

Browse files
committed
Use Locale.ROOT consistently for toLower/toUpperCase
Closes spring-projectsgh-33708
1 parent 23656ae commit 11d4272

File tree

23 files changed

+81
-59
lines changed

23 files changed

+81
-59
lines changed

spring-beans/src/main/java/org/springframework/beans/support/PropertyComparator.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -19,6 +19,7 @@
1919
import java.util.Arrays;
2020
import java.util.Comparator;
2121
import java.util.List;
22+
import java.util.Locale;
2223

2324
import org.apache.commons.logging.Log;
2425
import org.apache.commons.logging.LogFactory;
@@ -77,8 +78,8 @@ public int compare(T o1, T o2) {
7778
Object v1 = getPropertyValue(o1);
7879
Object v2 = getPropertyValue(o2);
7980
if (this.sortDefinition.isIgnoreCase() && (v1 instanceof String text1) && (v2 instanceof String text2)) {
80-
v1 = text1.toLowerCase();
81-
v2 = text2.toLowerCase();
81+
v1 = text1.toLowerCase(Locale.ROOT);
82+
v2 = text2.toLowerCase(Locale.ROOT);
8283
}
8384

8485
int result;

spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -19,6 +19,7 @@
1919
import java.sql.Connection;
2020
import java.sql.DatabaseMetaData;
2121
import java.sql.SQLException;
22+
import java.util.Locale;
2223

2324
import javax.sql.DataSource;
2425

@@ -155,7 +156,7 @@ public void initialize() {
155156
String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource,
156157
DatabaseMetaData::getDatabaseProductName);
157158
productName = JdbcUtils.commonDatabaseName(productName);
158-
if (productName != null && productName.toLowerCase().contains("hsql")) {
159+
if (productName != null && productName.toLowerCase(Locale.ROOT).contains("hsql")) {
159160
setUseDBLocks(false);
160161
setLockHandler(new SimpleSemaphore());
161162
}

spring-context/src/main/java/org/springframework/format/datetime/standard/MonthFormatter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MonthFormatter implements Formatter<Month> {
3434

3535
@Override
3636
public Month parse(String text, Locale locale) throws ParseException {
37-
return Month.valueOf(text.toUpperCase());
37+
return Month.valueOf(text.toUpperCase(Locale.ROOT));
3838
}
3939

4040
@Override

spring-context/src/main/java/org/springframework/scheduling/support/CronField.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.time.temporal.ChronoUnit;
2222
import java.time.temporal.Temporal;
2323
import java.time.temporal.ValueRange;
24+
import java.util.Locale;
2425
import java.util.function.BiFunction;
2526

2627
import org.springframework.lang.Nullable;
@@ -143,7 +144,7 @@ private static CronField parseList(String value, Type type, BiFunction<String, T
143144
}
144145

145146
private static String replaceOrdinals(String value, String[] list) {
146-
value = value.toUpperCase();
147+
value = value.toUpperCase(Locale.ROOT);
147148
for (int i = 0; i < list.length; i++) {
148149
String replacement = Integer.toString(i + 1);
149150
value = StringUtils.replace(value, list[i], replacement);

spring-core-test/src/main/java/org/springframework/aot/agent/InvocationsRecorderClassVisitor.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -17,6 +17,7 @@
1717
package org.springframework.aot.agent;
1818

1919
import java.util.HashSet;
20+
import java.util.Locale;
2021
import java.util.Set;
2122

2223
import org.springframework.asm.ClassVisitor;
@@ -40,6 +41,7 @@ class InvocationsRecorderClassVisitor extends ClassVisitor implements Opcodes {
4041

4142
private final ClassWriter classWriter;
4243

44+
4345
public InvocationsRecorderClassVisitor() {
4446
this(new ClassWriter(ClassWriter.COMPUTE_MAXS));
4547
}
@@ -49,6 +51,7 @@ private InvocationsRecorderClassVisitor(ClassWriter classWriter) {
4951
this.classWriter = classWriter;
5052
}
5153

54+
5255
public boolean isTransformed() {
5356
return this.isTransformed;
5457
}
@@ -64,6 +67,7 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str
6467
return new InvocationsRecorderMethodVisitor(mv);
6568
}
6669

70+
6771
@SuppressWarnings("deprecation")
6872
class InvocationsRecorderMethodVisitor extends MethodVisitor implements Opcodes {
6973

@@ -83,7 +87,6 @@ public InvocationsRecorderMethodVisitor(MethodVisitor mv) {
8387
super(SpringAsmInfo.ASM_VERSION, mv);
8488
}
8589

86-
8790
@Override
8891
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
8992
if (isOpcodeSupported(opcode) && shouldRecordMethodCall(owner, name)) {
@@ -116,21 +119,19 @@ public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootst
116119
super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
117120
}
118121

119-
120122
private boolean shouldRecordMethodCall(String owner, String method) {
121123
String methodReference = owner + "#" + method;
122124
return instrumentedMethods.contains(methodReference);
123125
}
124126

125127
private String rewriteMethodName(String owner, String methodName) {
126128
int classIndex = owner.lastIndexOf('/');
127-
return owner.substring(classIndex + 1).toLowerCase() + methodName;
129+
return owner.substring(classIndex + 1).toLowerCase(Locale.ROOT) + methodName;
128130
}
129131

130132
private String rewriteDescriptor(int opcode, String owner, String name, String descriptor) {
131133
return (opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.H_INVOKESTATIC) ? descriptor : "(L" + owner + ";" + descriptor.substring(1);
132134
}
133-
134135
}
135136

136137
}

spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.core.convert.support;
1818

19+
import java.util.Locale;
1920
import java.util.Set;
2021

2122
import org.springframework.core.convert.converter.Converter;
@@ -43,7 +44,7 @@ public Boolean convert(String source) {
4344
if (value.isEmpty()) {
4445
return null;
4546
}
46-
value = value.toLowerCase();
47+
value = value.toLowerCase(Locale.ROOT);
4748
if (trueValues.contains(value)) {
4849
return Boolean.TRUE;
4950
}

spring-core/src/main/java/org/springframework/core/env/SystemEnvironmentPropertySource.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.core.env;
1818

19+
import java.util.Locale;
1920
import java.util.Map;
2021

2122
import org.springframework.lang.Nullable;
@@ -109,7 +110,7 @@ protected final String resolvePropertyName(String name) {
109110
if (resolvedName != null) {
110111
return resolvedName;
111112
}
112-
String uppercasedName = name.toUpperCase();
113+
String uppercasedName = name.toUpperCase(Locale.ROOT);
113114
if (!name.equals(uppercasedName)) {
114115
resolvedName = checkPropertyName(uppercasedName);
115116
if (resolvedName != null) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.net.URISyntaxException;
2525
import java.net.URL;
2626
import java.net.URLConnection;
27+
import java.util.Locale;
2728

2829
import org.springframework.lang.Nullable;
2930

@@ -306,7 +307,7 @@ public static boolean isJarURL(URL url) {
306307
*/
307308
public static boolean isJarFileURL(URL url) {
308309
return (URL_PROTOCOL_FILE.equals(url.getProtocol()) &&
309-
url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION));
310+
url.getPath().toLowerCase(Locale.ROOT).endsWith(JAR_FILE_EXTENSION));
310311
}
311312

312313
/**

spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.expression.spel;
1818

19+
import java.util.Locale;
20+
1921
import org.springframework.core.SpringProperties;
2022
import org.springframework.lang.Nullable;
2123

@@ -46,7 +48,7 @@ public class SpelParserConfiguration {
4648
static {
4749
String compilerMode = SpringProperties.getProperty(SPRING_EXPRESSION_COMPILER_MODE_PROPERTY_NAME);
4850
defaultCompilerMode = (compilerMode != null ?
49-
SpelCompilerMode.valueOf(compilerMode.toUpperCase()) : SpelCompilerMode.OFF);
51+
SpelCompilerMode.valueOf(compilerMode.toUpperCase(Locale.ROOT)) : SpelCompilerMode.OFF);
5052
}
5153

5254

spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.expression.spel.ast;
1818

1919
import java.lang.reflect.Array;
20+
import java.util.Locale;
2021

2122
import org.springframework.asm.MethodVisitor;
2223
import org.springframework.asm.Type;
@@ -58,7 +59,7 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
5859
String typeName = (String) this.children[0].getValueInternal(state).getValue();
5960
Assert.state(typeName != null, "No type name");
6061
if (!typeName.contains(".") && Character.isLowerCase(typeName.charAt(0))) {
61-
TypeCode tc = TypeCode.valueOf(typeName.toUpperCase());
62+
TypeCode tc = TypeCode.valueOf(typeName.toUpperCase(Locale.ROOT));
6263
if (tc != TypeCode.OBJECT) {
6364
// It is a primitive type
6465
Class<?> clazz = makeArrayIfNecessary(tc.getType());

spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Collections;
2222
import java.util.Deque;
2323
import java.util.List;
24+
import java.util.Locale;
2425
import java.util.concurrent.ConcurrentHashMap;
2526
import java.util.concurrent.ConcurrentMap;
2627
import java.util.regex.Pattern;
@@ -750,7 +751,7 @@ private SpelNodeImpl eatPossiblyQualifiedId() {
750751
throw internalException( this.expressionString.length(), SpelMessage.OOD);
751752
}
752753
throw internalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN,
753-
"qualified ID", node.getKind().toString().toLowerCase());
754+
"qualified ID", node.getKind().toString().toLowerCase(Locale.ROOT));
754755
}
755756
return new QualifiedIdentifier(qualifiedIdPieces.getFirst().getStartPosition(),
756757
qualifiedIdPieces.getLast().getEndPosition(), qualifiedIdPieces.toArray(new SpelNodeImpl[0]));
@@ -942,7 +943,7 @@ private Token eatToken(TokenKind expectedKind) {
942943
}
943944
if (t.kind != expectedKind) {
944945
throw internalException(t.startPos, SpelMessage.NOT_EXPECTED_TOKEN,
945-
expectedKind.toString().toLowerCase(), t.getKind().toString().toLowerCase());
946+
expectedKind.toString().toLowerCase(Locale.ROOT), t.getKind().toString().toLowerCase(Locale.ROOT));
946947
}
947948
return t;
948949
}
@@ -1038,7 +1039,7 @@ public String toString(@Nullable Token t) {
10381039
if (t.getKind().hasPayload()) {
10391040
return t.stringValue();
10401041
}
1041-
return t.kind.toString().toLowerCase();
1042+
return t.kind.toString().toLowerCase(Locale.ROOT);
10421043
}
10431044

10441045
private void checkOperands(Token token, @Nullable SpelNodeImpl left, @Nullable SpelNodeImpl right) {

spring-expression/src/main/java/org/springframework/expression/spel/standard/Tokenizer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Arrays;
2121
import java.util.List;
22+
import java.util.Locale;
2223

2324
import org.springframework.expression.spel.InternalParseException;
2425
import org.springframework.expression.spel.SpelMessage;
@@ -457,7 +458,7 @@ private void lexIdentifier() {
457458
// Check if this is the alternative (textual) representation of an operator (see
458459
// ALTERNATIVE_OPERATOR_NAMES).
459460
if (subarray.length == 2 || subarray.length == 3) {
460-
String asString = new String(subarray).toUpperCase();
461+
String asString = new String(subarray).toUpperCase(Locale.ROOT);
461462
int idx = Arrays.binarySearch(ALTERNATIVE_OPERATOR_NAMES, asString);
462463
if (idx >= 0) {
463464
pushOneCharOrTwoCharToken(TokenKind.valueOf(asString), start, subarray);

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ protected List<SqlParameter> reconcileParameters(List<SqlParameter> parameters)
385385
if (meta.isReturnParameter()) {
386386
param = declaredParams.get(getFunctionReturnName());
387387
if (param == null && !getOutParameterNames().isEmpty()) {
388-
param = declaredParams.get(getOutParameterNames().get(0).toLowerCase());
388+
param = declaredParams.get(getOutParameterNames().get(0).toLowerCase(Locale.ROOT));
389389
}
390390
if (param == null) {
391391
throw new InvalidDataAccessApiUsageException(
@@ -488,15 +488,15 @@ public Map<String, Object> matchInParameterValuesWithCallParameters(SqlParameter
488488
String parameterName = parameter.getName();
489489
String parameterNameToMatch = obtainMetaDataProvider().parameterNameToUse(parameterName);
490490
if (parameterNameToMatch != null) {
491-
callParameterNames.put(parameterNameToMatch.toLowerCase(), parameterName);
491+
callParameterNames.put(parameterNameToMatch.toLowerCase(Locale.ROOT), parameterName);
492492
}
493493
if (parameterName != null) {
494494
if (parameterSource.hasValue(parameterName)) {
495495
matchedParameters.put(parameterName,
496496
SqlParameterSourceUtils.getTypedValue(parameterSource, parameterName));
497497
}
498498
else {
499-
String lowerCaseName = parameterName.toLowerCase();
499+
String lowerCaseName = parameterName.toLowerCase(Locale.ROOT);
500500
if (parameterSource.hasValue(lowerCaseName)) {
501501
matchedParameters.put(parameterName,
502502
SqlParameterSourceUtils.getTypedValue(parameterSource, lowerCaseName));
@@ -556,7 +556,7 @@ else if (logger.isInfoEnabled()) {
556556
String parameterName = parameter.getName();
557557
String parameterNameToMatch = provider.parameterNameToUse(parameterName);
558558
if (parameterNameToMatch != null) {
559-
callParameterNames.put(parameterNameToMatch.toLowerCase(), parameterName);
559+
callParameterNames.put(parameterNameToMatch.toLowerCase(Locale.ROOT), parameterName);
560560
}
561561
}
562562
}
@@ -681,7 +681,7 @@ protected String createParameterBinding(SqlParameter parameter) {
681681
}
682682

683683
private static String lowerCase(@Nullable String paramName) {
684-
return (paramName != null ? paramName.toLowerCase() : "");
684+
return (paramName != null ? paramName.toLowerCase(Locale.ROOT) : "");
685685
}
686686

687687
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java

+3-2
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-2024 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.
@@ -18,6 +18,7 @@
1818

1919
import java.sql.DatabaseMetaData;
2020
import java.sql.SQLException;
21+
import java.util.Locale;
2122

2223
import org.springframework.lang.Nullable;
2324

@@ -73,7 +74,7 @@ public String metaDataSchemaNameToUse(@Nullable String schemaName) {
7374

7475
// Use current user schema if no schema specified...
7576
String userName = getUserName();
76-
return (userName != null ? userName.toUpperCase() : null);
77+
return (userName != null ? userName.toUpperCase(Locale.ROOT) : null);
7778
}
7879

7980
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java

+3-2
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-2024 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.
@@ -18,6 +18,7 @@
1818

1919
import java.sql.DatabaseMetaData;
2020
import java.sql.SQLException;
21+
import java.util.Locale;
2122

2223
import org.springframework.lang.Nullable;
2324

@@ -45,7 +46,7 @@ public String metaDataSchemaNameToUse(@Nullable String schemaName) {
4546

4647
// Use current user schema if no schema specified...
4748
String userName = getUserName();
48-
return (userName != null ? userName.toUpperCase() : null);
49+
return (userName != null ? userName.toUpperCase(Locale.ROOT) : null);
4950
}
5051

5152
}

0 commit comments

Comments
 (0)