Use toLowerCase() and toUpperCase() with Locale.ENGLISH

This commit updates all `toLowerCase()` and `toUpperCase` invocations to
use the variant that takes a `Locale` to avoid locale-specific side
effect.

Closes gh-12213
This commit is contained in:
Stephane Nicoll
2018-02-26 17:49:03 +01:00
parent 915eaf3447
commit b4a7e1d64b
38 changed files with 148 additions and 87 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2018 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.
@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.cloudfoundry;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -107,7 +109,7 @@ class CloudFoundrySecurityInterceptor extends HandlerInterceptorAdapter {
String authorization = request.getHeader("Authorization");
String bearerPrefix = "bearer ";
if (authorization == null
|| !authorization.toLowerCase().startsWith(bearerPrefix)) {
|| !authorization.toLowerCase(Locale.ENGLISH).startsWith(bearerPrefix)) {
throw new CloudFoundryAuthorizationException(Reason.MISSING_AUTHORIZATION,
"Authorization header is missing or invalid");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2018 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.
@@ -19,6 +19,7 @@ package org.springframework.boot.actuate.endpoint;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -104,7 +105,7 @@ public class DataSourcePublicMetrics implements PublicMetrics {
return "datasource.primary";
}
if (name.length() > DATASOURCE_SUFFIX.length()
&& name.toLowerCase().endsWith(DATASOURCE_SUFFIX.toLowerCase())) {
&& name.toLowerCase(Locale.ENGLISH).endsWith(DATASOURCE_SUFFIX.toLowerCase())) {
name = name.substring(0, name.length() - DATASOURCE_SUFFIX.length());
}
return "datasource." + name;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -16,6 +16,7 @@
package org.springframework.boot.actuate.endpoint;
import java.util.Locale;
import java.util.Map;
import org.springframework.boot.actuate.health.CompositeHealthIndicator;
@@ -91,7 +92,7 @@ public class HealthEndpoint extends AbstractEndpoint<Health> {
* @return the key
*/
private String getKey(String name) {
int index = name.toLowerCase().indexOf("healthindicator");
int index = name.toLowerCase(Locale.ENGLISH).indexOf("healthindicator");
if (index > 0) {
return name.substring(0, index);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2018 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.
@@ -24,6 +24,7 @@ import java.lang.management.ThreadMXBean;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import org.springframework.boot.actuate.metrics.Metric;
import org.springframework.core.Ordered;
@@ -188,7 +189,7 @@ public class SystemPublicMetrics implements PublicMetrics, Ordered {
* @return a metric friendly name
*/
private String beautifyGcName(String name) {
return StringUtils.replace(name, " ", "_").toLowerCase();
return StringUtils.replace(name, " ", "_").toLowerCase(Locale.ENGLISH);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -16,6 +16,8 @@
package org.springframework.boot.actuate.endpoint.jmx;
import java.util.Locale;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.actuate.endpoint.Endpoint;
@@ -52,7 +54,7 @@ public class LoggersEndpointMBean extends EndpointMBean {
@ManagedOperation(description = "Set log level for a given logger")
public void setLogLevel(String loggerName, String logLevel) {
Assert.notNull(logLevel, "LogLevel must not be null");
LogLevel level = LogLevel.valueOf(logLevel.toUpperCase());
LogLevel level = LogLevel.valueOf(logLevel.toUpperCase(Locale.ENGLISH));
getEndpoint().setLogLevel(loggerName, level);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -20,6 +20,7 @@ import java.security.Principal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@@ -151,7 +152,7 @@ public class HealthMvcEndpoint extends AbstractEndpointMvcAdapter<HealthEndpoint
private HttpStatus getStatus(Health health) {
String code = health.getStatus().getCode();
if (code != null) {
code = code.toLowerCase().replace('_', '-');
code = code.toLowerCase(Locale.ENGLISH).replace('_', '-');
for (String candidate : RelaxedNames.forCamelCase(code)) {
HttpStatus status = this.statusMapping.get(candidate);
if (status != null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@@ -16,6 +16,7 @@
package org.springframework.boot.actuate.endpoint.mvc;
import java.util.Locale;
import java.util.Map;
import org.springframework.boot.actuate.endpoint.LoggersEndpoint;
@@ -78,7 +79,8 @@ public class LoggersMvcEndpoint extends EndpointMvcAdapter {
private LogLevel getLogLevel(Map<String, String> configuration) {
String level = configuration.get("configuredLevel");
try {
return (level == null ? null : LogLevel.valueOf(level.toUpperCase()));
return (level == null ? null
: LogLevel.valueOf(level.toUpperCase(Locale.ENGLISH)));
}
catch (IllegalArgumentException ex) {
throw new InvalidLogLevelException(level);

View File

@@ -23,6 +23,7 @@ import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -165,7 +166,7 @@ public class WebRequestTraceFilter extends OncePerRequestFilter implements Order
Enumeration<String> names = request.getHeaderNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
if (!excludedHeaders.contains(name.toLowerCase())) {
if (!excludedHeaders.contains(name.toLowerCase(Locale.ENGLISH))) {
headers.put(name, getHeaderValue(request, name));
}
}