Skip to content

Commit

Permalink
adds LOCALE.English to each toUpperCase/toLowerCase calls to avoid th…
Browse files Browse the repository at this point in the history
…e famous Turkish problem

refs: #7464
  • Loading branch information
robfrank committed Jun 6, 2017
1 parent ee5c782 commit 3b8cf9e
Show file tree
Hide file tree
Showing 107 changed files with 352 additions and 318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ private void parseOptions(final Map<String, Object> iOptions) {
if (iOptions == null || iOptions.size() == 0)
return;

final Object connType = iOptions.get(PARAM_CONNECTION_STRATEGY.toLowerCase());
final Object connType = iOptions.get(PARAM_CONNECTION_STRATEGY.toLowerCase(Locale.ENGLISH));
if (connType != null)
connectionStrategy = CONNECTION_STRATEGY.valueOf(connType.toString().toUpperCase());
connectionStrategy = CONNECTION_STRATEGY.valueOf(connType.toString().toUpperCase(Locale.ENGLISH));

// CREATE A COPY TO AVOID POST OPEN MANIPULATION BY USER
connectionOptions = new HashMap<String, Object>(iOptions);
Expand Down Expand Up @@ -1466,7 +1466,7 @@ public int getClusterIdByName(final String iClusterName) {
if (Character.isDigit(iClusterName.charAt(0)))
return Integer.parseInt(iClusterName);

final OCluster cluster = clusterMap.get(iClusterName.toLowerCase());
final OCluster cluster = clusterMap.get(iClusterName.toLowerCase(Locale.ENGLISH));
if (cluster == null)
return -1;

Expand Down Expand Up @@ -1510,12 +1510,12 @@ public Integer execute(OChannelBinaryAsynchClient network, OStorageRemoteSession
final int clusterId = network.readShort();

final OClusterRemote cluster = new OClusterRemote();
cluster.configure(OStorageRemote.this, clusterId, iClusterName.toLowerCase());
cluster.configure(OStorageRemote.this, clusterId, iClusterName.toLowerCase(Locale.ENGLISH));

if (clusters.length <= clusterId)
clusters = Arrays.copyOf(clusters, clusterId + 1);
clusters[cluster.getId()] = cluster;
clusterMap.put(cluster.getName().toLowerCase(), cluster);
clusterMap.put(cluster.getName().toLowerCase(Locale.ENGLISH), cluster);

return clusterId;
} finally {
Expand Down Expand Up @@ -2360,7 +2360,7 @@ private void readDatabaseInformation(final OChannelBinaryAsynchClient network) t
String clusterName = network.readString();
final int clusterId = network.readShort();
if (clusterName != null) {
clusterName = clusterName.toLowerCase();
clusterName = clusterName.toLowerCase(Locale.ENGLISH);

if (network.getSrvProtocolVersion() < 24)
network.readString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public boolean isEchoEnabled() {
protected boolean isPropertyEnabled(final String iPropertyName) {
String v = properties.get(iPropertyName);
if (v != null) {
v = v.toLowerCase();
v = v.toLowerCase(Locale.ENGLISH);
return v.equals("true") || v.equals("on");
}
return false;
Expand Down Expand Up @@ -334,7 +334,7 @@ protected RESULT execute(String iCommand) {
if (i > 0) {
commandLowerCase += " ";
}
commandLowerCase += commandWords[i].toLowerCase();
commandLowerCase += commandWords[i].toLowerCase(Locale.ENGLISH);
}

for (Entry<Method, Object> entry : getConsoleMethods().entrySet()) {
Expand Down Expand Up @@ -442,7 +442,7 @@ protected Method getMethod(String iCommand) {
// COMMENT: JUMP IT
return null;

final String commandLowerCase = iCommand.toLowerCase();
final String commandLowerCase = iCommand.toLowerCase(Locale.ENGLISH);

final Map<Method, Object> methodMap = getConsoleMethods();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static String java2unicode(final String iInput) {
for (int j = 0; j < 4 - hex.length(); j++)
// Prepend zeros because unicode requires 4 digits
result.append('0');
result.append(hex.toLowerCase()); // standard unicode format.
result.append(hex.toLowerCase(Locale.ENGLISH)); // standard unicode format.
// ostr.append(hex.toLowerCase(Locale.ENGLISH));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.orientechnologies.common.parser.OVariableParserListener;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;

import java.util.Locale;

/**
* Console ANSI utility class that supports most of the ANSI amenities.
*
Expand Down Expand Up @@ -99,7 +101,7 @@ public Object resolve(final String iVariable) {

final String[] codes = code.split(":");
for (int i = 0; i < codes.length; ++i)
buffer.append(OAnsiCode.valueOf(codes[i].toUpperCase()));
buffer.append(OAnsiCode.valueOf(codes[i].toUpperCase(Locale.ENGLISH)));

if (pos > -1) {
buffer.append(text);
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/com/orientechnologies/orient/core/Orient.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ else if (thisObject != null && thatObject != null)

protected Orient() {
super(true);
this.os = System.getProperty("os.name").toLowerCase();
this.os = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
threadGroup = new ThreadGroup("OrientDB");
threadGroup.setDaemon(false);
}
Expand Down Expand Up @@ -462,7 +462,7 @@ public OStorage loadStorage(String iURL) {

engineLock.readLock().lock();
try {
final OEngine engine = engines.get(engineName.toLowerCase());
final OEngine engine = engines.get(engineName.toLowerCase(Locale.ENGLISH));

if (engine == null)
throw new OConfigurationException(
Expand Down Expand Up @@ -521,7 +521,7 @@ public OStorage loadStorage(String iURL) {

final String dbName = registerDatabaseByPath ? dbPath : engine.getNameFromPath(dbPath);

final String dbNameCaseInsensitive = dbName.toLowerCase();
final String dbNameCaseInsensitive = dbName.toLowerCase(Locale.ENGLISH);

OStorage storage;
// SEARCH IF ALREADY USED
Expand Down Expand Up @@ -558,7 +558,7 @@ public OStorage getStorage(final String name) {

engineLock.readLock().lock();
try {
return storages.get(name.toLowerCase());
return storages.get(name.toLowerCase(Locale.ENGLISH));
} finally {
engineLock.readLock().unlock();
}
Expand Down Expand Up @@ -648,7 +648,7 @@ public void unregisterStorageByName(final String name) {
throw new IllegalArgumentException("Storage name is null");

final String dbName = registerDatabaseByPath ? name : OIOUtils.getRelativePathIfAny(name, null);
final OStorage stg = storages.get(dbName.toLowerCase());
final OStorage stg = storages.get(dbName.toLowerCase(Locale.ENGLISH));
unregisterStorage(stg);
}

Expand Down Expand Up @@ -677,7 +677,7 @@ public void unregisterStorage(final OStorage storage) {
}

for (String dbName : storagesToRemove)
storages.remove(dbName.toLowerCase());
storages.remove(dbName.toLowerCase(Locale.ENGLISH));

// UNREGISTER STORAGE FROM ENGINES IN CASE IS CACHED
for (OEngine engine : engines.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@

import com.orientechnologies.common.comparator.ODefaultComparator;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

/**
* Case insensitive collate.
Expand All @@ -41,7 +38,7 @@ public String getName() {

public Object transform(final Object obj) {
if (obj instanceof String)
return ((String) obj).toLowerCase();
return ((String) obj).toLowerCase(Locale.ENGLISH);

if(obj instanceof Set){
Set result = new HashSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ protected Object executeSQLScript(final String iText, final ODatabaseDocument db
String next = lastCommand.substring("begin ".length()).trim();
if (OStringSerializerHelper.startsWithIgnoreCase(next, "isolation ")) {
next = next.substring("isolation ".length()).trim();
db.getTransaction().setIsolationLevel(OTransaction.ISOLATION_LEVEL.valueOf(next.toUpperCase()));
db.getTransaction().setIsolationLevel(OTransaction.ISOLATION_LEVEL.valueOf(next.toUpperCase(Locale.ENGLISH)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public OScriptManager() {
registerEngine(OSQLScriptEngine.NAME, new OSQLScriptEngineFactory());

for (ScriptEngineFactory f : scriptEngineManager.getEngineFactories()) {
registerEngine(f.getLanguageName().toLowerCase(), f);
registerEngine(f.getLanguageName().toLowerCase(Locale.ENGLISH), f);

if (defaultLanguage == null)
defaultLanguage = f.getLanguageName();
Expand All @@ -84,15 +84,15 @@ public OScriptManager() {
}

public String getFunctionDefinition(final OFunction iFunction) {
final OScriptFormatter formatter = formatters.get(iFunction.getLanguage().toLowerCase());
final OScriptFormatter formatter = formatters.get(iFunction.getLanguage().toLowerCase(Locale.ENGLISH));
if (formatter == null)
throw new IllegalArgumentException("Cannot find script formatter for the language '" + iFunction.getLanguage() + "'");

return formatter.getFunctionDefinition(iFunction);
}

public String getFunctionInvoke(final OFunction iFunction, final Object[] iArgs) {
final OScriptFormatter formatter = formatters.get(iFunction.getLanguage().toLowerCase());
final OScriptFormatter formatter = formatters.get(iFunction.getLanguage().toLowerCase(Locale.ENGLISH));
if (formatter == null)
throw new IllegalArgumentException("Cannot find script formatter for the language '" + iFunction.getLanguage() + "'");

Expand Down Expand Up @@ -137,15 +137,15 @@ public boolean existsEngine(String iLanguage) {
if (iLanguage == null)
return false;

iLanguage = iLanguage.toLowerCase();
iLanguage = iLanguage.toLowerCase(Locale.ENGLISH);
return engines.containsKey(iLanguage);
}

public ScriptEngine getEngine(final String iLanguage) {
if (iLanguage == null)
throw new OCommandScriptException("No language was specified");

final String lang = iLanguage.toLowerCase();
final String lang = iLanguage.toLowerCase(Locale.ENGLISH);

final ScriptEngineFactory scriptEngineFactory = engines.get(lang);
if (scriptEngineFactory == null)
Expand Down Expand Up @@ -346,7 +346,7 @@ public OScriptManager registerEngine(final String iLanguage, final ScriptEngineF
}

public OScriptManager registerFormatter(final String iLanguage, final OScriptFormatter iFormatterImpl) {
formatters.put(iLanguage.toLowerCase(), iFormatterImpl);
formatters.put(iLanguage.toLowerCase(Locale.ENGLISH), iFormatterImpl);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Map<String, Object> getVariables() {
}

public Object getVariable(final String iName) {
final String name = iName.trim().toUpperCase();
final String name = iName.trim().toUpperCase(Locale.ENGLISH);

if ("DEPTH".startsWith(name))
return getDepth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.orientechnologies.orient.core.storage.OChecksumMode;

import java.io.PrintStream;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.ConsoleHandler;
Expand Down Expand Up @@ -999,7 +1000,7 @@ public static void dumpConfiguration(final PrintStream out) {

if (!lastSection.equals(section)) {
out.print("- ");
out.println(section.toUpperCase());
out.println(section.toUpperCase(Locale.ENGLISH));
lastSection = section;
}
out.print(" + ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,17 @@ public OStorageConfiguration load(final Map<String, Object> iProperties) throws
initConfiguration();

final String compressionMethod = (String) iProperties
.get(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getKey().toLowerCase());
.get(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getKey().toLowerCase(Locale.ENGLISH));
if (compressionMethod != null)
// SAVE COMPRESSION METHOD IN CONFIGURATION
configuration.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD, compressionMethod);

final String encryptionMethod = (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey().toLowerCase());
final String encryptionMethod = (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey().toLowerCase(Locale.ENGLISH));
if (encryptionMethod != null)
// SAVE ENCRYPTION METHOD IN CONFIGURATION
configuration.setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD, encryptionMethod);

final String encryptionKey = (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey().toLowerCase());
final String encryptionKey = (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey().toLowerCase(Locale.ENGLISH));
if (encryptionKey != null)
// SAVE ENCRYPTION KEY IN CONFIGURATION
configuration.setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY, encryptionKey);
Expand Down Expand Up @@ -882,21 +882,21 @@ public void setValidation(final boolean validation) {

protected void bindPropertiesToContext(final Map<String, Object> iProperties) {
final String compressionMethod = iProperties != null ?
(String) iProperties.get(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getKey().toLowerCase()) :
(String) iProperties.get(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getKey().toLowerCase(Locale.ENGLISH)) :
null;
if (compressionMethod != null)
// SAVE COMPRESSION METHOD IN CONFIGURATION
getContextConfiguration().setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD, compressionMethod);

final String encryptionMethod = iProperties != null ?
(String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey().toLowerCase()) :
(String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey().toLowerCase(Locale.ENGLISH)) :
null;
if (encryptionMethod != null)
// SAVE ENCRYPTION METHOD IN CONFIGURATION
getContextConfiguration().setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD, encryptionMethod);

final String encryptionKey =
iProperties != null ? (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey().toLowerCase()) : null;
iProperties != null ? (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey().toLowerCase(Locale.ENGLISH)) : null;
if (encryptionKey != null)
// SAVE ENCRYPTION KEY IN CONFIGURATION
getContextConfiguration().setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY, encryptionKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.orientechnologies.orient.core.storage.OStorage;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down Expand Up @@ -379,9 +380,9 @@ private void checkForClose() {
*/
public Object setProperty(final String iName, final Object iValue) {
if (iValue != null) {
return properties.put(iName.toLowerCase(), iValue);
return properties.put(iName.toLowerCase(Locale.ENGLISH), iValue);
} else {
return properties.remove(iName.toLowerCase());
return properties.remove(iName.toLowerCase(Locale.ENGLISH));
}
}

Expand All @@ -392,7 +393,7 @@ public Object setProperty(final String iName, final Object iValue) {
* @return The previous value if any, otherwise null
*/
public Object getProperty(final String iName) {
return properties.get(iName.toLowerCase());
return properties.get(iName.toLowerCase(Locale.ENGLISH));
}

private static final class PoolData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ public int getClusters() {
@Override
public boolean existsCluster(final String iClusterName) {
checkIfActive();
return storage.getClusterNames().contains(iClusterName.toLowerCase());
return storage.getClusterNames().contains(iClusterName.toLowerCase(Locale.ENGLISH));
}

@Override
Expand All @@ -1326,7 +1326,7 @@ public int getClusterIdByName(final String iClusterName) {
return -1;

checkIfActive();
return storage.getClusterIdByName(iClusterName.toLowerCase());
return storage.getClusterIdByName(iClusterName.toLowerCase(Locale.ENGLISH));
}

@Override
Expand Down Expand Up @@ -1479,14 +1479,14 @@ public boolean dropCluster(final int iClusterId, final boolean iTruncate) {
@Override
public Object setProperty(final String iName, final Object iValue) {
if (iValue == null)
return properties.remove(iName.toLowerCase());
return properties.remove(iName.toLowerCase(Locale.ENGLISH));
else
return properties.put(iName.toLowerCase(), iValue);
return properties.put(iName.toLowerCase(Locale.ENGLISH), iValue);
}

@Override
public Object getProperty(final String iName) {
return properties.get(iName.toLowerCase());
return properties.get(iName.toLowerCase(Locale.ENGLISH));
}

@Override
Expand Down Expand Up @@ -1600,7 +1600,7 @@ public <DB extends ODatabase> DB set(final ATTRIBUTES iAttribute, final Object i
throw new IllegalArgumentException("Timezone can't be null");

// for backward compatibility, until 2.1.13 OrientDB accepted timezones in lowercase as well
TimeZone timeZoneValue = TimeZone.getTimeZone(stringValue.toUpperCase());
TimeZone timeZoneValue = TimeZone.getTimeZone(stringValue.toUpperCase(Locale.ENGLISH));
if (timeZoneValue.equals(TimeZone.getTimeZone("GMT"))) {
timeZoneValue = TimeZone.getTimeZone(stringValue);
}
Expand Down
Loading

0 comments on commit 3b8cf9e

Please sign in to comment.