Skip to content

Commit

Permalink
Use Locale.ROOT for locale neutral, case insensitive comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
HasiniSama committed Nov 7, 2024
1 parent 7a8b354 commit b8f3a75
Show file tree
Hide file tree
Showing 68 changed files with 104 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private ApplicationContext createContext(final ScopedProxyMode scopedProxyMode)
break;
}
else if (annDef.getMetadata().getMetaAnnotationTypes(type).contains(javax.inject.Scope.class.getName())) {
metadata.setScopeName(type.substring(type.length() - 13, type.length() - 6).toLowerCase());
metadata.setScopeName(type.substring(type.length() - 13, type.length() - 6).toLowerCase(Locale.ROOT));
metadata.setScopedProxyMode(scopedProxyMode);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public int compare(T o1, T o2) {
Object v1 = getPropertyValue(o1);
Object v2 = getPropertyValue(o2);
if (this.sortDefinition.isIgnoreCase() && (v1 instanceof String) && (v2 instanceof String)) {
v1 = ((String) v1).toLowerCase();
v2 = ((String) v2).toLowerCase();
v1 = ((String) v1).toLowerCase(Locale.ROOT);
v2 = ((String) v2).toLowerCase(Locale.ROOT);
}

int result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public void testPropertyOverrideConfigurerWithInvalidKey() {
}
catch (BeanInitializationException ex) {
// prove that the processor chokes on the invalid key
assertThat(ex.getMessage().toLowerCase().contains("argh")).isTrue();
assertThat(ex.getMessage().toLowerCase(Locale.ROOT).contains("argh")).isTrue();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,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 @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -464,7 +465,7 @@ public String[] getAllowedFields() {
* <p>The default implementation of this method stores disallowed field patterns
* in {@linkplain PropertyAccessorUtils#canonicalPropertyName(String) canonical}
* form. As of Spring Framework 5.2.21, the default implementation also transforms
* disallowed field patterns to {@linkplain String#toLowerCase() lowercase} to
* disallowed field patterns to {@linkplain String#toLowerCase(Locale.ROOT) lowercase} to
* support case-insensitive pattern matching in {@link #isAllowed}. Subclasses
* which override this method must therefore take both of these transformations
* into account.
Expand All @@ -482,7 +483,8 @@ public void setDisallowedFields(@Nullable String... disallowedFields) {
else {
String[] fieldPatterns = new String[disallowedFields.length];
for (int i = 0; i < fieldPatterns.length; i++) {
fieldPatterns[i] = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]).toLowerCase();
String field = PropertyAccessorUtils.canonicalPropertyName(disallowedFields[i]);
fieldPatterns[i] = field.toLowerCase(Locale.ROOT);
}
this.disallowedFields = fieldPatterns;
}
Expand Down Expand Up @@ -825,7 +827,7 @@ protected boolean isAllowed(String field) {
String[] allowed = getAllowedFields();
String[] disallowed = getDisallowedFields();
return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field)) &&
(ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field.toLowerCase())));
(ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field.toLowerCase(Locale.ROOT))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ open class BeanDefinitionDsl internal constructor (private val init: BeanDefinit
role: Role? = null) {

val customizer = BeanDefinitionCustomizer { bd ->
scope?.let { bd.scope = scope.name.toLowerCase() }
scope?.let { bd.scope = scope.name.toLowerCase(Locale.ROOT) }
isLazyInit?.let { bd.isLazyInit = isLazyInit }
isPrimary?.let { bd.isPrimary = isPrimary }
isAutowireCandidate?.let { bd.isAutowireCandidate = isAutowireCandidate }
Expand Down Expand Up @@ -221,7 +221,7 @@ open class BeanDefinitionDsl internal constructor (private val init: BeanDefinit
crossinline function: BeanSupplierContext.() -> T) {

val customizer = BeanDefinitionCustomizer { bd ->
scope?.let { bd.scope = scope.name.toLowerCase() }
scope?.let { bd.scope = scope.name.toLowerCase(Locale.ROOT) }
isLazyInit?.let { bd.isLazyInit = isLazyInit }
isPrimary?.let { bd.isPrimary = isPrimary }
isAutowireCandidate?.let { bd.isAutowireCandidate = isAutowireCandidate }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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
Expand Up @@ -182,10 +182,10 @@ public MimeType(String type, String subtype, @Nullable Map<String, String> param
Assert.hasLength(subtype, "'subtype' must not be empty");
checkToken(type);
checkToken(subtype);
this.type = type.toLowerCase(Locale.ENGLISH);
this.subtype = subtype.toLowerCase(Locale.ENGLISH);
this.type = type.toLowerCase(Locale.ROOT);
this.subtype = subtype.toLowerCase(Locale.ROOT);
if (!CollectionUtils.isEmpty(parameters)) {
Map<String, String> map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH);
Map<String, String> map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ROOT);
parameters.forEach((parameter, value) -> {
checkParameters(parameter, value);
map.put(parameter, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,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 @@ -2947,7 +2947,7 @@ enum RequestMethod {
*/
@Override
public String toString() {
return "method: " + name().toLowerCase();
return "method: " + name().toLowerCase(Locale.ROOT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,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 +942,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 +1038,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 @@ -60,7 +60,7 @@ public void testSimpleAccess01() {
public void testStringClass() {
evaluate("new java.lang.String('hello').charAt(2)", 'l', Character.class);
evaluate("new java.lang.String('hello').charAt(2).equals('l'.charAt(0))", true, Boolean.class);
evaluate("'HELLO'.toLowerCase()", "hello", String.class);
evaluate("'HELLO'.toLowerCase(Locale.ROOT)", "hello", String.class);
evaluate("' abcba '.trim()", "abcba", String.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3768,7 +3768,7 @@ public void constructorReference_SPR13781() {

// The actual expression from the bug report. It fails if the ENGLISH reference fails
// to pop the type reference for Locale off the stack (if it isn't popped then
// toLowerCase() will be called with a Locale parameter). In this situation the
// toLowerCase(Locale.ROOT) will be called with a Locale parameter). In this situation the
// code generation for ENGLISH should notice there is something on the stack that
// is not required and pop it off.
expression = parser.parseExpression("#userId.toString().toLowerCase(T(java.util.Locale).ENGLISH)");
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 @@ -680,7 +680,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
Expand Up @@ -282,7 +282,7 @@ else if (isStoresUpperCaseIdentifiers()) {
return identifierName.toUpperCase();
}
else if (isStoresLowerCaseIdentifiers()) {
return identifierName.toLowerCase();
return identifierName.toLowerCase(Locale.ROOT);
}
else {
return identifierName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ else if (isStoresUpperCaseIdentifiers()) {
return tableName.toUpperCase();
}
else if (isStoresLowerCaseIdentifiers()) {
return tableName.toLowerCase();
return tableName.toLowerCase(Locale.ROOT);
}
else {
return tableName;
Expand All @@ -250,7 +250,7 @@ else if (isStoresUpperCaseIdentifiers()) {
return catalogName.toUpperCase();
}
else if (isStoresLowerCaseIdentifiers()) {
return catalogName.toLowerCase();
return catalogName.toLowerCase(Locale.ROOT);
}
else {
return catalogName;
Expand All @@ -267,7 +267,7 @@ else if (isStoresUpperCaseIdentifiers()) {
return schemaName.toUpperCase();
}
else if (isStoresLowerCaseIdentifiers()) {
return schemaName.toLowerCase();
return schemaName.toLowerCase(Locale.ROOT);
}
else {
return schemaName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSource p
values.add(SqlParameterSourceUtils.getTypedValue(parameterSource, column));
}
else {
String lowerCaseName = column.toLowerCase();
String lowerCaseName = column.toLowerCase(Locale.ROOT);
if (parameterSource.hasValue(lowerCaseName)) {
values.add(SqlParameterSourceUtils.getTypedValue(parameterSource, lowerCaseName));
}
Expand Down Expand Up @@ -251,7 +251,7 @@ public List<Object> matchInParameterValuesWithInsertColumns(Map<String, ?> inPar
for (String column : this.tableColumns) {
Object value = inParameters.get(column);
if (value == null) {
value = inParameters.get(column.toLowerCase());
value = inParameters.get(column.toLowerCase(Locale.ROOT));
if (value == null) {
for (Map.Entry<String, ?> entry : inParameters.entrySet()) {
if (column.equalsIgnoreCase(entry.getKey())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static Map<String, String> extractCaseInsensitiveParameterNames(SqlParame
String[] paramNames = parameterSource.getParameterNames();
if (paramNames != null) {
for (String name : paramNames) {
caseInsensitiveParameterNames.put(name.toLowerCase(), name);
caseInsensitiveParameterNames.put(name.toLowerCase(Locale.ROOT), name);
}
}
return caseInsensitiveParameterNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void modifyCustomNativeHeader() {

StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SUBSCRIBE, extHeaders);
String accountId = headers.getFirstNativeHeader("accountId");
headers.setNativeHeader("accountId", accountId.toLowerCase());
headers.setNativeHeader("accountId", accountId.toLowerCase(Locale.ROOT));

Map<String, List<String>> actual = headers.toNativeHeaderMap();
assertThat(actual.size()).isEqualTo(3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ public void setCharacterEncoding(@Nullable String characterEncoding) {
private void updateContentTypeHeader() {
if (StringUtils.hasLength(this.contentType)) {
String value = this.contentType;
if (StringUtils.hasLength(this.characterEncoding) && !this.contentType.toLowerCase().contains(CHARSET_PREFIX)) {
if (StringUtils.hasLength(this.characterEncoding) &&
!this.contentType.toLowerCase(Locale.ROOT).contains(CHARSET_PREFIX)) {
value += ';' + CHARSET_PREFIX + this.characterEncoding;
}
doAddHeaderValue(HttpHeaders.CONTENT_TYPE, value, true);
Expand Down Expand Up @@ -484,7 +485,7 @@ public void setContentType(@Nullable String contentType) {
}
catch (IllegalArgumentException ex) {
// Try to get charset value anyway
int charsetIndex = contentType.toLowerCase().indexOf(CHARSET_PREFIX);
int charsetIndex = contentType.toLowerCase(Locale.ROOT).indexOf(CHARSET_PREFIX);
if (charsetIndex != -1) {
this.characterEncoding = contentType.substring(charsetIndex + CHARSET_PREFIX.length());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void setExplicitCharacterEncoding(String characterEncoding) {
private void updateContentTypePropertyAndHeader() {
if (this.contentType != null) {
String value = this.contentType;
if (this.characterEncodingSet && !value.toLowerCase().contains(CHARSET_PREFIX)) {
if (this.characterEncodingSet && !value.toLowerCase(Locale.ROOT).contains(CHARSET_PREFIX)) {
value += ';' + CHARSET_PREFIX + getCharacterEncoding();
this.contentType = value;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ public void setContentType(@Nullable String contentType) {
}
catch (Exception ex) {
// Try to get charset value anyway
int charsetIndex = contentType.toLowerCase().indexOf(CHARSET_PREFIX);
int charsetIndex = contentType.toLowerCase(Locale.ROOT).indexOf(CHARSET_PREFIX);
if (charsetIndex != -1) {
setExplicitCharacterEncoding(contentType.substring(charsetIndex + CHARSET_PREFIX.length()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*
* <ul>
* <li>Spring Expression Language (SpEL) expression &mdash; for example:
* <pre style="code">#{systemProperties['os.name'].toLowerCase().contains('mac')}</pre>
* <pre style="code">#{systemProperties['os.name'].toLowerCase(Locale.ROOT).contains('mac')}</pre>
* <li>Placeholder for a property available in the Spring
* {@link org.springframework.core.env.Environment Environment} &mdash; for example:
* <pre style="code">${smoke.tests.enabled}</pre>
Expand Down Expand Up @@ -193,7 +193,7 @@ private <A extends Annotation> boolean evaluateExpression(String expression, boo
return (Boolean) result;
}
else if (result instanceof String) {
String str = ((String) result).trim().toLowerCase();
String str = ((String) result).trim().toLowerCase(Locale.ROOT);
if ("true".equals(str)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* {@literal @}Target({ElementType.TYPE, ElementType.METHOD})
* {@literal @}Retention(RetentionPolicy.RUNTIME)
* {@literal @}DisabledIf(
* expression = "#{systemProperties['os.name'].toLowerCase().contains('mac')}",
* expression = "#{systemProperties['os.name'].toLowerCase(Locale.ROOT).contains('mac')}",
* reason = "Disabled on Mac OS"
* )
* public {@literal @}interface DisabledOnMac {}
Expand Down Expand Up @@ -94,7 +94,7 @@
*
* <ul>
* <li>Spring Expression Language (SpEL) expression &mdash; for example:
* <pre style="code">@DisabledIf("#{systemProperties['os.name'].toLowerCase().contains('mac')}")</pre>
* <pre style="code">@DisabledIf("#{systemProperties['os.name'].toLowerCase(Locale.ROOT).contains('mac')}")</pre>
* <li>Placeholder for a property available in the Spring
* {@link org.springframework.core.env.Environment Environment} &mdash; for example:
* <pre style="code">@DisabledIf("${smoke.tests.disabled}")</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* {@literal @}Target({ElementType.TYPE, ElementType.METHOD})
* {@literal @}Retention(RetentionPolicy.RUNTIME)
* {@literal @}EnabledIf(
* expression = "#{systemProperties['os.name'].toLowerCase().contains('mac')}",
* expression = "#{systemProperties['os.name'].toLowerCase(Locale.ROOT).contains('mac')}",
* reason = "Enabled on Mac OS"
* )
* public {@literal @}interface EnabledOnMac {}
Expand Down Expand Up @@ -93,7 +93,7 @@
*
* <ul>
* <li>Spring Expression Language (SpEL) expression &mdash; for example:
* <pre style="code">@EnabledIf("#{systemProperties['os.name'].toLowerCase().contains('mac')}")</pre>
* <pre style="code">@EnabledIf("#{systemProperties['os.name'].toLowerCase(Locale.ROOT).contains('mac')}")</pre>
* <li>Placeholder for a property available in the Spring
* {@link org.springframework.core.env.Environment Environment} &mdash; for example:
* <pre style="code">@EnabledIf("${smoke.tests.enabled}")</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void standardDefaultMode() {

@Test
void overriddenDefaultMode() {
setGlobalFlag("\t" + OVERRIDE.name().toLowerCase() + " ");
setGlobalFlag("\t" + OVERRIDE.name().toLowerCase(Locale.ROOT) + " ");
assertThat(searchEnclosingClass(OuterTestCase.class)).isFalse();
assertThat(searchEnclosingClass(OuterTestCase.NestedTestCase.class)).isFalse();
assertThat(searchEnclosingClass(OuterTestCase.NestedTestCase.DoubleNestedTestCase.class)).isFalse();
Expand Down
Loading

0 comments on commit b8f3a75

Please sign in to comment.