Skip to content

Commit

Permalink
Use Locale.ROOT consistently for toLower/toUpperCase
Browse files Browse the repository at this point in the history
Closes gh-33708
  • Loading branch information
jhoeller committed Oct 16, 2024
1 parent 23656ae commit 11d4272
Show file tree
Hide file tree
Showing 23 changed files with 81 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
Expand All @@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -77,8 +78,8 @@ public int compare(T o1, T o2) {
Object v1 = getPropertyValue(o1);
Object v2 = getPropertyValue(o2);
if (this.sortDefinition.isIgnoreCase() && (v1 instanceof String text1) && (v2 instanceof String text2)) {
v1 = text1.toLowerCase();
v2 = text2.toLowerCase();
v1 = text1.toLowerCase(Locale.ROOT);
v2 = text2.toLowerCase(Locale.ROOT);
}

int result;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 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.
Expand All @@ -19,6 +19,7 @@
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Locale;

import javax.sql.DataSource;

Expand Down Expand Up @@ -155,7 +156,7 @@ public void initialize() {
String productName = JdbcUtils.extractDatabaseMetaData(this.dataSource,
DatabaseMetaData::getDatabaseProductName);
productName = JdbcUtils.commonDatabaseName(productName);
if (productName != null && productName.toLowerCase().contains("hsql")) {
if (productName != null && productName.toLowerCase(Locale.ROOT).contains("hsql")) {
setUseDBLocks(false);
setLockHandler(new SimpleSemaphore());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MonthFormatter implements Formatter<Month> {

@Override
public Month parse(String text, Locale locale) throws ParseException {
return Month.valueOf(text.toUpperCase());
return Month.valueOf(text.toUpperCase(Locale.ROOT));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.ValueRange;
import java.util.Locale;
import java.util.function.BiFunction;

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

private static String replaceOrdinals(String value, String[] list) {
value = value.toUpperCase();
value = value.toUpperCase(Locale.ROOT);
for (int i = 0; i < list.length; i++) {
String replacement = Integer.toString(i + 1);
value = StringUtils.replace(value, list[i], replacement);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
Expand All @@ -17,6 +17,7 @@
package org.springframework.aot.agent;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

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

private final ClassWriter classWriter;


public InvocationsRecorderClassVisitor() {
this(new ClassWriter(ClassWriter.COMPUTE_MAXS));
}
Expand All @@ -49,6 +51,7 @@ private InvocationsRecorderClassVisitor(ClassWriter classWriter) {
this.classWriter = classWriter;
}


public boolean isTransformed() {
return this.isTransformed;
}
Expand All @@ -64,6 +67,7 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str
return new InvocationsRecorderMethodVisitor(mv);
}


@SuppressWarnings("deprecation")
class InvocationsRecorderMethodVisitor extends MethodVisitor implements Opcodes {

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


@Override
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
if (isOpcodeSupported(opcode) && shouldRecordMethodCall(owner, name)) {
Expand Down Expand Up @@ -116,21 +119,19 @@ public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootst
super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments);
}


private boolean shouldRecordMethodCall(String owner, String method) {
String methodReference = owner + "#" + method;
return instrumentedMethods.contains(methodReference);
}

private String rewriteMethodName(String owner, String methodName) {
int classIndex = owner.lastIndexOf('/');
return owner.substring(classIndex + 1).toLowerCase() + methodName;
return owner.substring(classIndex + 1).toLowerCase(Locale.ROOT) + methodName;
}

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

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
Expand All @@ -16,6 +16,7 @@

package org.springframework.core.convert.support;

import java.util.Locale;
import java.util.Set;

import org.springframework.core.convert.converter.Converter;
Expand Down Expand Up @@ -43,7 +44,7 @@ public Boolean convert(String source) {
if (value.isEmpty()) {
return null;
}
value = value.toLowerCase();
value = value.toLowerCase(Locale.ROOT);
if (trueValues.contains(value)) {
return Boolean.TRUE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 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.
Expand All @@ -16,6 +16,7 @@

package org.springframework.core.env;

import java.util.Locale;
import java.util.Map;

import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -109,7 +110,7 @@ protected final String resolvePropertyName(String name) {
if (resolvedName != null) {
return resolvedName;
}
String uppercasedName = name.toUpperCase();
String uppercasedName = name.toUpperCase(Locale.ROOT);
if (!name.equals(uppercasedName)) {
resolvedName = checkPropertyName(uppercasedName);
if (resolvedName != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Locale;

import org.springframework.lang.Nullable;

Expand Down Expand Up @@ -306,7 +307,7 @@ public static boolean isJarURL(URL url) {
*/
public static boolean isJarFileURL(URL url) {
return (URL_PROTOCOL_FILE.equals(url.getProtocol()) &&
url.getPath().toLowerCase().endsWith(JAR_FILE_EXTENSION));
url.getPath().toLowerCase(Locale.ROOT).endsWith(JAR_FILE_EXTENSION));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.expression.spel;

import java.util.Locale;

import org.springframework.core.SpringProperties;
import org.springframework.lang.Nullable;

Expand Down Expand Up @@ -46,7 +48,7 @@ public class SpelParserConfiguration {
static {
String compilerMode = SpringProperties.getProperty(SPRING_EXPRESSION_COMPILER_MODE_PROPERTY_NAME);
defaultCompilerMode = (compilerMode != null ?
SpelCompilerMode.valueOf(compilerMode.toUpperCase()) : SpelCompilerMode.OFF);
SpelCompilerMode.valueOf(compilerMode.toUpperCase(Locale.ROOT)) : SpelCompilerMode.OFF);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.expression.spel.ast;

import java.lang.reflect.Array;
import java.util.Locale;

import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Type;
Expand Down Expand Up @@ -58,7 +59,7 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
String typeName = (String) this.children[0].getValueInternal(state).getValue();
Assert.state(typeName != null, "No type name");
if (!typeName.contains(".") && Character.isLowerCase(typeName.charAt(0))) {
TypeCode tc = TypeCode.valueOf(typeName.toUpperCase());
TypeCode tc = TypeCode.valueOf(typeName.toUpperCase(Locale.ROOT));
if (tc != TypeCode.OBJECT) {
// It is a primitive type
Class<?> clazz = makeArrayIfNecessary(tc.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -750,7 +751,7 @@ private SpelNodeImpl eatPossiblyQualifiedId() {
throw internalException( this.expressionString.length(), SpelMessage.OOD);
}
throw internalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN,
"qualified ID", node.getKind().toString().toLowerCase());
"qualified ID", node.getKind().toString().toLowerCase(Locale.ROOT));
}
return new QualifiedIdentifier(qualifiedIdPieces.getFirst().getStartPosition(),
qualifiedIdPieces.getLast().getEndPosition(), qualifiedIdPieces.toArray(new SpelNodeImpl[0]));
Expand Down Expand Up @@ -942,7 +943,7 @@ private Token eatToken(TokenKind expectedKind) {
}
if (t.kind != expectedKind) {
throw internalException(t.startPos, SpelMessage.NOT_EXPECTED_TOKEN,
expectedKind.toString().toLowerCase(), t.getKind().toString().toLowerCase());
expectedKind.toString().toLowerCase(Locale.ROOT), t.getKind().toString().toLowerCase(Locale.ROOT));
}
return t;
}
Expand Down Expand Up @@ -1038,7 +1039,7 @@ public String toString(@Nullable Token t) {
if (t.getKind().hasPayload()) {
return t.stringValue();
}
return t.kind.toString().toLowerCase();
return t.kind.toString().toLowerCase(Locale.ROOT);
}

private void checkOperands(Token token, @Nullable SpelNodeImpl left, @Nullable SpelNodeImpl right) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import org.springframework.expression.spel.InternalParseException;
import org.springframework.expression.spel.SpelMessage;
Expand Down Expand Up @@ -457,7 +458,7 @@ private void lexIdentifier() {
// Check if this is the alternative (textual) representation of an operator (see
// ALTERNATIVE_OPERATOR_NAMES).
if (subarray.length == 2 || subarray.length == 3) {
String asString = new String(subarray).toUpperCase();
String asString = new String(subarray).toUpperCase(Locale.ROOT);
int idx = Arrays.binarySearch(ALTERNATIVE_OPERATOR_NAMES, asString);
if (idx >= 0) {
pushOneCharOrTwoCharToken(TokenKind.valueOf(asString), start, subarray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ protected List<SqlParameter> reconcileParameters(List<SqlParameter> parameters)
if (meta.isReturnParameter()) {
param = declaredParams.get(getFunctionReturnName());
if (param == null && !getOutParameterNames().isEmpty()) {
param = declaredParams.get(getOutParameterNames().get(0).toLowerCase());
param = declaredParams.get(getOutParameterNames().get(0).toLowerCase(Locale.ROOT));
}
if (param == null) {
throw new InvalidDataAccessApiUsageException(
Expand Down Expand Up @@ -488,15 +488,15 @@ public Map<String, Object> matchInParameterValuesWithCallParameters(SqlParameter
String parameterName = parameter.getName();
String parameterNameToMatch = obtainMetaDataProvider().parameterNameToUse(parameterName);
if (parameterNameToMatch != null) {
callParameterNames.put(parameterNameToMatch.toLowerCase(), parameterName);
callParameterNames.put(parameterNameToMatch.toLowerCase(Locale.ROOT), parameterName);
}
if (parameterName != null) {
if (parameterSource.hasValue(parameterName)) {
matchedParameters.put(parameterName,
SqlParameterSourceUtils.getTypedValue(parameterSource, parameterName));
}
else {
String lowerCaseName = parameterName.toLowerCase();
String lowerCaseName = parameterName.toLowerCase(Locale.ROOT);
if (parameterSource.hasValue(lowerCaseName)) {
matchedParameters.put(parameterName,
SqlParameterSourceUtils.getTypedValue(parameterSource, lowerCaseName));
Expand Down Expand Up @@ -556,7 +556,7 @@ else if (logger.isInfoEnabled()) {
String parameterName = parameter.getName();
String parameterNameToMatch = provider.parameterNameToUse(parameterName);
if (parameterNameToMatch != null) {
callParameterNames.put(parameterNameToMatch.toLowerCase(), parameterName);
callParameterNames.put(parameterNameToMatch.toLowerCase(Locale.ROOT), parameterName);
}
}
}
Expand Down Expand Up @@ -681,7 +681,7 @@ protected String createParameterBinding(SqlParameter parameter) {
}

private static String lowerCase(@Nullable String paramName) {
return (paramName != null ? paramName.toLowerCase() : "");
return (paramName != null ? paramName.toLowerCase(Locale.ROOT) : "");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2024 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.
Expand All @@ -18,6 +18,7 @@

import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Locale;

import org.springframework.lang.Nullable;

Expand Down Expand Up @@ -73,7 +74,7 @@ public String metaDataSchemaNameToUse(@Nullable String schemaName) {

// Use current user schema if no schema specified...
String userName = getUserName();
return (userName != null ? userName.toUpperCase() : null);
return (userName != null ? userName.toUpperCase(Locale.ROOT) : null);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2024 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.
Expand All @@ -18,6 +18,7 @@

import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Locale;

import org.springframework.lang.Nullable;

Expand Down Expand Up @@ -45,7 +46,7 @@ public String metaDataSchemaNameToUse(@Nullable String schemaName) {

// Use current user schema if no schema specified...
String userName = getUserName();
return (userName != null ? userName.toUpperCase() : null);
return (userName != null ? userName.toUpperCase(Locale.ROOT) : null);
}

}
Loading

0 comments on commit 11d4272

Please sign in to comment.