Commit b4a7e1d6 authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent 915eaf34
/*
* 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");
}
......
/*
* 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;
......
/*
* 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);
}
......
/*
* 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);
}
}
/*
* 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);
}
......
/*
* 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) {
......
/*
* 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);
......
......@@ -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));
}
}
......
/*
* 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.autoconfigure.cache;
import java.util.Locale;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
......@@ -50,7 +52,8 @@ class CacheCondition extends SpringBootCondition {
}
CacheType cacheType = CacheConfigurations
.getType(((AnnotationMetadata) metadata).getClassName());
String value = resolver.getProperty("type").replace('-', '_').toUpperCase();
String value = resolver.getProperty("type").replace('-', '_')
.toUpperCase(Locale.ENGLISH);
if (value.equals(cacheType.name())) {
return ConditionOutcome.match(message.because(value + " cache type"));
}
......
/*
* 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.
......@@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.springframework.beans.factory.BeanFactory;
......@@ -399,7 +400,7 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit
string.append(StringUtils.collectionToCommaDelimitedString(this.types));
}
string.append("; SearchStrategy: ");
string.append(this.strategy.toString().toLowerCase());
string.append(this.strategy.toString().toLowerCase(Locale.ENGLISH));
string.append(")");
return string.toString();
}
......
/*
* 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.
......@@ -17,6 +17,7 @@
package org.springframework.boot.autoconfigure.data.cassandra;
import java.util.List;
import java.util.Locale;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
......@@ -114,7 +115,8 @@ public class CassandraDataAutoConfiguration {
session.setKeyspaceName(this.properties.getKeyspaceName());
String name = this.propertyResolver.getProperty("schemaAction",
SchemaAction.NONE.name());
SchemaAction schemaAction = SchemaAction.valueOf(name.toUpperCase());
SchemaAction schemaAction = SchemaAction.valueOf(
name.toUpperCase(Locale.ENGLISH));
session.setSchemaAction(schemaAction);
return session;
}
......
/*
* 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.
......@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.jdbc;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Locale;
import javax.sql.DataSource;
......@@ -173,7 +174,7 @@ public enum EmbeddedDatabaseConnection {
if (productName == null) {
return false;
}
productName = productName.toUpperCase();
productName = productName.toUpperCase(Locale.ENGLISH);
EmbeddedDatabaseConnection[] candidates = EmbeddedDatabaseConnection.values();
for (EmbeddedDatabaseConnection candidate : candidates) {
if (candidate != NONE && productName.contains(candidate.name())) {
......
/*
* 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.autoconfigure.session;
import java.util.Locale;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.ObjectProvider;
......@@ -100,7 +102,8 @@ public class SessionAutoConfiguration {
if (storeType != null) {
throw new IllegalArgumentException("No session repository could be "
+ "auto-configured, check your configuration (session store "
+ "type is '" + storeType.name().toLowerCase() + "')");
+ "type is '" + storeType.name().toLowerCase(Locale.ENGLISH)
+ "')");
}
throw new IllegalArgumentException("No Spring Session store is "
+ "configured: set the 'spring.session.store-type' property");
......
/*
* 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.autoconfigure.session;
import java.util.Locale;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
......@@ -45,7 +47,8 @@ class SessionCondition extends SpringBootCondition {
return ConditionOutcome.noMatch(
message.didNotFind("spring.session.store-type property").atAll());
}
String value = resolver.getProperty("store-type").replace('-', '_').toUpperCase();
String value = resolver.getProperty("store-type").replace('-', '_')
.toUpperCase(Locale.ENGLISH);
if (value.equals(sessionStoreType.name())) {
return ConditionOutcome.match(message
.found("spring.session.store-type property").items(sessionStoreType));
......
/*
* 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.
......@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.web;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
......@@ -78,7 +79,7 @@ public abstract class AbstractErrorController implements ErrorController {
if (parameter == null) {
return false;
}
return !"false".equals(parameter.toLowerCase());
return !"false".equals(parameter.toLowerCase(Locale.ENGLISH));
}
protected HttpStatus getStatus(HttpServletRequest request) {
......
/*
* 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.
......@@ -27,6 +27,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.jar.Manifest;
import groovy.lang.Grab;
......@@ -129,9 +130,10 @@ abstract class ArchiveCommand extends OptionParsingCommand {
+ this.type + " and at least one source file must be specified");
File output = new File((String) nonOptionArguments.remove(0));
Assert.isTrue(output.getName().toLowerCase().endsWith("." + this.type),
"The output '" + output + "' is not a " + this.type.toUpperCase()
+ " file.");
Assert.isTrue(
output.getName().toLowerCase(Locale.ENGLISH).endsWith("." + this.type),
"The output '" + output + "' is not a " + this.type.toUpperCase(
Locale.ENGLISH) + " file.");
deleteIfExists(output);
GroovyCompiler compiler = createCompiler(options);
......
......@@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
......@@ -306,7 +307,8 @@ public class SysVinitLaunchScriptIT {
private String buildImage(DockerClient docker) {
String dockerfile = "src/test/resources/conf/" + this.os + "/" + this.version
+ "/Dockerfile";
String tag = "spring-boot-it/" + this.os.toLowerCase() + ":" + this.version;
String tag = "spring-boot-it/" + this.os.toLowerCase(Locale.ENGLISH) + ":"
+ this.version;
BuildImageResultCallback resultCallback = new BuildImageResultCallback() {
private List<BuildResponseItem> items = new ArrayList<BuildResponseItem>();
......
/*
* 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 sample.data.gemfire.service;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import javax.annotation.PostConstruct;
......@@ -126,7 +127,7 @@ public class GemstoneServiceImpl implements GemstoneService {
}
Gemstone validate(Gemstone gemstone) {
if (!APPROVED_GEMS.contains(gemstone.getName().toUpperCase())) {
if (!APPROVED_GEMS.contains(gemstone.getName().toUpperCase(Locale.ENGLISH))) {
// NOTE if the Gemstone is not valid, throw error...
// Should cause transaction to rollback in GemFire!
System.err.printf("Illegal Gemstone [%1$s]!%n", gemstone.getName());
......
/*
* 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.
......@@ -23,6 +23,7 @@ import java.util.Collections;
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.regex.Matcher;
......@@ -158,7 +159,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource<Class<?>
matcher.group(1) + '-' + StringUtils.uncapitalize(matcher.group(2)));
}
matcher.appendTail(result);
return result.toString().toLowerCase();
return result.toString().toLowerCase(Locale.ENGLISH);
}
private String dotAppend(String prefix, String postfix) {
......
/*
* 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.
......@@ -23,6 +23,7 @@ import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.json.JSONArray;
import org.json.JSONObject;
......@@ -183,7 +184,7 @@ class JsonReader {
private Deprecation.Level parseDeprecationLevel(String value) {
if (value != null) {
try {
return Deprecation.Level.valueOf(value.toUpperCase());
return Deprecation.Level.valueOf(value.toUpperCase(Locale.ENGLISH));
}
catch (IllegalArgumentException e) {
// let's use the default
......
/*
* 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.
......@@ -23,6 +23,7 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
......@@ -197,7 +198,7 @@ public class ConfigurationMetadata {
previous = current;
}
return dashed.toString().toLowerCase();
return dashed.toString().toLowerCase(Locale.ENGLISH);
}
private static <T extends Comparable<T>> List<T> flattenValues(Map<?, List<T>> map) {
......
/*
* 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.
......@@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
......@@ -45,13 +46,14 @@ public final class Layouts {
if (file == null) {
throw new IllegalArgumentException("File must not be null");
}
if (file.getName().toLowerCase().endsWith(".jar")) {
if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
return new Jar();
}
if (file.getName().toLowerCase().endsWith(".war")) {
if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".war")) {
return new War();
}
if (file.isDirectory() || file.getName().toLowerCase().endsWith(".zip")) {
if (file.isDirectory()
|| file.getName().toLowerCase(Locale.ENGLISH).endsWith(".zip")) {
return new Expanded();
}
throw new IllegalStateException("Unable to deduce layout for '" + file + "'");
......
/*
* 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.
......@@ -23,6 +23,7 @@ import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Locale;
import org.springframework.util.ReflectionUtils;
......@@ -128,7 +129,8 @@ public class RunProcess {
// There's a bug in the Windows VM (https://bugs.openjdk.java.net/browse/JDK-8023130)
// that means we need to avoid inheritIO
private static boolean isInheritIOBroken() {
if (!System.getProperty("os.name", "none").toLowerCase().contains("windows")) {
if (!System.getProperty("os.name", "none").toLowerCase(Locale.ENGLISH)
.contains("windows")) {
return false;
}
String runtime = System.getProperty("java.runtime.version");
......
/*
* 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.
......@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.jar.Manifest;
......@@ -489,7 +490,7 @@ public class PropertiesLauncher extends Launcher {
}
private Archive getArchive(File file) throws IOException {
String name = file.getName().toLowerCase();
String name = file.getName().toLowerCase(Locale.ENGLISH);
if (name.endsWith(".jar") || name.endsWith(".zip")) {
return new JarFileArchive(file);
}
......@@ -566,7 +567,8 @@ public class PropertiesLauncher extends Launcher {
if (path.startsWith("./")) {
path = path.substring(2);
}
if (path.toLowerCase().endsWith(".jar") || path.toLowerCase().endsWith(".zip")) {
String lowercasePath = path.toLowerCase(Locale.ENGLISH);
if (lowercasePath.endsWith(".jar") || lowercasePath.endsWith(".zip")) {
return path;
}
if (path.endsWith("/*")) {
......
/*
* 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.
......@@ -17,6 +17,7 @@
package org.springframework.boot.loader.util;
import java.util.HashSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
......@@ -188,7 +189,8 @@ public abstract class SystemPropertyUtils {
}
if (propVal == null) {
// Try uppercase with underscores as well.
propVal = System.getenv(key.toUpperCase().replace('.', '_'));
propVal = System.getenv(key.toUpperCase(Locale.ENGLISH)
.replace('.', '_'));
}
if (propVal != null) {
return propVal;
......
/*
* 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.
......@@ -16,6 +16,8 @@
package org.springframework.boot.ansi;
import java.util.Locale;
import org.springframework.util.Assert;
/**
......@@ -35,7 +37,7 @@ public abstract class AnsiOutput {
private static Boolean ansiCapable;
private static final String OPERATING_SYSTEM_NAME = System.getProperty("os.name")
.toLowerCase();
.toLowerCase(Locale.ENGLISH);
private static final String ENCODE_START = "\033[";
......
/*
* 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.
......@@ -18,6 +18,7 @@ package org.springframework.boot.bind;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
......@@ -184,7 +185,7 @@ public class PropertySourcesPropertyValues implements PropertyValues {
// Probably could not convert to Object, weird, but ignorable
}
if (value == null) {
value = source.getProperty(propertyName.toUpperCase());
value = source.getProperty(propertyName.toUpperCase(Locale.ENGLISH));
}
putIfAbsent(propertyName, value, source);
}
......
/*
* 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.
......@@ -17,6 +17,7 @@
package org.springframework.boot.bind;
import java.util.EnumSet;
import java.util.Locale;
import java.util.Set;
import org.springframework.core.convert.ConversionFailedException;
......@@ -127,7 +128,8 @@ class RelaxedConversionService implements ConversionService {
source = source.trim();
for (T candidate : (Set<T>) EnumSet.allOf(this.enumType)) {
RelaxedNames names = new RelaxedNames(
candidate.name().replace('_', '-').toLowerCase());
candidate.name().replace('_', '-')
.toLowerCase(Locale.ENGLISH));
for (String name : names) {
if (name.equals(source)) {
return candidate;
......
/*
* 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.
......@@ -18,6 +18,7 @@ package org.springframework.boot.bind;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -91,7 +92,7 @@ public final class RelaxedNames implements Iterable<String> {
@Override
public String apply(String value) {
return value.isEmpty() ? value : value.toLowerCase();
return value.isEmpty() ? value : value.toLowerCase(Locale.ENGLISH);
}
},
......@@ -100,7 +101,7 @@ public final class RelaxedNames implements Iterable<String> {
@Override
public String apply(String value) {
return value.isEmpty() ? value : value.toUpperCase();
return value.isEmpty() ? value : value.toUpperCase(Locale.ENGLISH);
}
};
......@@ -225,7 +226,7 @@ public final class RelaxedNames implements Iterable<String> {
}
StringBuilder builder = new StringBuilder();
for (String field : SEPARATED_TO_CAMEL_CASE_PATTERN.split(value)) {
field = (caseInsensitive ? field.toLowerCase() : field);
field = (caseInsensitive ? field.toLowerCase(Locale.ENGLISH) : field);
builder.append(
builder.length() == 0 ? field : StringUtils.capitalize(field));
}
......
/*
* 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.
......@@ -16,6 +16,8 @@
package org.springframework.boot.context.config;
import java.util.Locale;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.ansi.AnsiOutput.Enabled;
import org.springframework.boot.bind.RelaxedPropertyResolver;
......@@ -40,7 +42,8 @@ public class AnsiOutputApplicationListener
event.getEnvironment(), "spring.output.ansi.");
if (resolver.containsProperty("enabled")) {
String enabled = resolver.getProperty("enabled");
AnsiOutput.setEnabled(Enum.valueOf(Enabled.class, enabled.toUpperCase()));
AnsiOutput.setEnabled(Enum.valueOf(Enabled.class,
enabled.toUpperCase(Locale.ENGLISH)));
}
if (resolver.containsProperty("console-available")) {
......
/*
* 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.
......@@ -26,6 +26,7 @@ import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.jar.JarFile;
import org.apache.commons.logging.Log;
......@@ -177,7 +178,7 @@ public abstract class AbstractEmbeddedServletContainerFactory
this.logger.debug("Code archive: " + file);
}
if (file != null && file.exists() && !file.isDirectory()
&& file.getName().toLowerCase().endsWith(extension)) {
&& file.getName().toLowerCase(Locale.ENGLISH).endsWith(extension)) {
return file.getAbsoluteFile();
}
return null;
......
/*
* 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.
......@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.apache.commons.logging.Log;
......@@ -144,9 +145,9 @@ public class PropertySourcesLoader {
}
private boolean canLoadFileExtension(PropertySourceLoader loader, Resource resource) {
String filename = resource.getFilename().toLowerCase();
String filename = resource.getFilename().toLowerCase(Locale.ENGLISH);
for (String extension : loader.getFileExtensions()) {
if (filename.endsWith("." + extension.toLowerCase())) {
if (filename.endsWith("." + extension.toLowerCase(Locale.ENGLISH))) {
return true;
}
}
......
......@@ -19,6 +19,7 @@ package org.springframework.boot.jdbc;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
......@@ -133,7 +134,7 @@ public enum DatabaseDriver {
@Override
protected boolean matchProductName(String productName) {
return super.matchProductName(productName)
|| productName.toLowerCase().startsWith("firebird");
|| productName.toLowerCase(Locale.ENGLISH).startsWith("firebird");
}
},
......@@ -146,7 +147,7 @@ public enum DatabaseDriver {
@Override
protected boolean matchProductName(String productName) {
return super.matchProductName(productName)
|| productName.toLowerCase().startsWith("db2/");
|| productName.toLowerCase(Locale.ENGLISH).startsWith("db2/");
}
},
......@@ -170,7 +171,7 @@ public enum DatabaseDriver {
@Override
protected boolean matchProductName(String productName) {
return super.matchProductName(productName)
|| productName.toLowerCase().contains("as/400");
|| productName.toLowerCase(Locale.ENGLISH).contains("as/400");
}
},
......@@ -222,7 +223,7 @@ public enum DatabaseDriver {
* @return the identifier
*/
public String getId() {
return name().toLowerCase();
return name().toLowerCase(Locale.ENGLISH);
}
protected boolean matchProductName(String productName) {
......@@ -230,7 +231,7 @@ public enum DatabaseDriver {
}
protected Collection<String> getUrlPrefixes() {
return Collections.singleton(this.name().toLowerCase());
return Collections.singleton(this.name().toLowerCase(Locale.ENGLISH));
}
/**
......@@ -265,7 +266,8 @@ public enum DatabaseDriver {
public static DatabaseDriver fromJdbcUrl(String url) {
if (StringUtils.hasLength(url)) {
Assert.isTrue(url.startsWith("jdbc"), "URL must start with 'jdbc'");
String urlWithoutPrefix = url.substring("jdbc".length()).toLowerCase();
String urlWithoutPrefix = url.substring("jdbc".length())
.toLowerCase(Locale.ENGLISH);
for (DatabaseDriver driver : values()) {
for (String urlPrefix : driver.getUrlPrefixes()) {
String prefix = ":" + urlPrefix + ":";
......
/*
* 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.
......@@ -17,6 +17,7 @@
package org.springframework.boot.logging;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
......@@ -370,7 +371,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
if ("false".equalsIgnoreCase(level)) {
return LogLevel.OFF;
}
return LogLevel.valueOf(level.toUpperCase());
return LogLevel.valueOf(level.toUpperCase(Locale.ENGLISH));
}
private void registerShutdownHookIfNecessary(Environment environment,
......
/*
* 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.
......@@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
......@@ -250,7 +251,8 @@ public class ApplicationPidFileWriter
private final String[] properties;
SystemProperty(String name) {
this.properties = new String[] { name.toUpperCase(), name.toLowerCase() };
this.properties = new String[] { name.toUpperCase(Locale.ENGLISH),
name.toLowerCase(Locale.ENGLISH) };
}
@Override
......
/*
* 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.
......@@ -17,6 +17,7 @@
package org.springframework.boot.system;
import java.io.File;
import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
......@@ -113,10 +114,10 @@ public class EmbeddedServerPortFileWriter
String extension = StringUtils.getFilenameExtension(this.file.getName());
name = name.substring(0, name.length() - extension.length() - 1);
if (isUpperCase(name)) {
name = name + "-" + contextName.toUpperCase();
name = name + "-" + contextName.toUpperCase(Locale.ENGLISH);
}
else {
name = name + "-" + contextName.toLowerCase();
name = name + "-" + contextName.toLowerCase(Locale.ENGLISH);
}
if (StringUtils.hasLength(extension)) {
name = name + "." + extension;
......
/*
* 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.web.servlet;
import java.util.Locale;
import javax.servlet.MultipartConfigElement;
import org.springframework.util.Assert;
......@@ -110,7 +112,7 @@ public class MultipartConfigFactory {
private long parseSize(String size) {
Assert.hasLength(size, "Size must not be empty");
size = size.toUpperCase();
size = size.toUpperCase(Locale.ENGLISH);
if (size.endsWith("KB")) {
return Long.valueOf(size.substring(0, size.length() - 2)) * 1024;
}
......
/*
* 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.system;
import java.io.File;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import org.junit.After;
......@@ -103,7 +104,7 @@ public class EmbeddedServerPortFileWriterTests {
@Test
public void createUpperCaseManagementPortFile() throws Exception {
File file = this.temporaryFolder.newFile();
file = new File(file.getParentFile(), file.getName().toUpperCase());
file = new File(file.getParentFile(), file.getName().toUpperCase(Locale.ENGLISH));
EmbeddedServerPortFileWriter listener = new EmbeddedServerPortFileWriter(file);
listener.onApplicationEvent(mockEvent("management", 9090));
String managementFile = file.getName();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment