Skip to content

Commit

Permalink
8311943: Cleanup usages of toLowerCase() and toUpperCase() in java.base
Browse files Browse the repository at this point in the history
Reviewed-by: naoto
  • Loading branch information
Glavo authored and naotoj committed Aug 16, 2023
1 parent 13f6450 commit b32d641
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 38 deletions.
39 changes: 20 additions & 19 deletions src/java.base/macosx/classes/apple/security/KeychainStore.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -181,7 +181,7 @@ public Key engineGetKey(String alias, char[] password)
password = Long.toString(random.nextLong()).toCharArray();
}

Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));

if (!(entry instanceof KeyEntry keyEntry)) {
return null;
Expand Down Expand Up @@ -271,7 +271,7 @@ public Key engineGetKey(String alias, char[] password)
public Certificate[] engineGetCertificateChain(String alias) {
permissionCheck();

Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));

if (entry instanceof KeyEntry keyEntry) {
if (keyEntry.chain == null) {
Expand Down Expand Up @@ -302,7 +302,7 @@ public Certificate[] engineGetCertificateChain(String alias) {
public Certificate engineGetCertificate(String alias) {
permissionCheck();

Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));

if (entry != null) {
if (entry instanceof TrustedCertEntry) {
Expand Down Expand Up @@ -337,7 +337,7 @@ public String getValue() {
public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam)
throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException {
if (engineIsCertificateEntry(alias)) {
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
if (entry instanceof TrustedCertEntry tEntry) {
return new KeyStore.TrustedCertificateEntry(
tEntry.cert, Set.of(
Expand All @@ -359,7 +359,7 @@ public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter
public Date engineGetCreationDate(String alias) {
permissionCheck();

Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));

if (entry != null) {
if (entry instanceof TrustedCertEntry) {
Expand Down Expand Up @@ -427,7 +427,7 @@ public void engineSetKeyEntry(String alias, Key key, char[] password,
entry.chainRefs = new long[entry.chain.length];
}

String lowerAlias = alias.toLowerCase();
String lowerAlias = alias.toLowerCase(Locale.ROOT);
if (entries.get(lowerAlias) != null) {
deletedEntries.put(lowerAlias, entries.get(lowerAlias));
}
Expand Down Expand Up @@ -491,7 +491,7 @@ public void engineSetKeyEntry(String alias, byte[] key,
entry.chainRefs = new long[entry.chain.length];
}

String lowerAlias = alias.toLowerCase();
String lowerAlias = alias.toLowerCase(Locale.ROOT);
if (entries.get(lowerAlias) != null) {
deletedEntries.put(lowerAlias, entries.get(alias));
}
Expand Down Expand Up @@ -521,9 +521,10 @@ public void engineDeleteEntry(String alias)
{
permissionCheck();

String lowerAlias = alias.toLowerCase(Locale.ROOT);
synchronized(entries) {
Object entry = entries.remove(alias.toLowerCase());
deletedEntries.put(alias.toLowerCase(), entry);
Object entry = entries.remove(lowerAlias);
deletedEntries.put(lowerAlias, entry);
}
}

Expand All @@ -546,7 +547,7 @@ public Enumeration<String> engineAliases() {
*/
public boolean engineContainsAlias(String alias) {
permissionCheck();
return entries.containsKey(alias.toLowerCase());
return entries.containsKey(alias.toLowerCase(Locale.ROOT));
}

/**
Expand All @@ -568,7 +569,7 @@ public int engineSize() {
*/
public boolean engineIsKeyEntry(String alias) {
permissionCheck();
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
return entry instanceof KeyEntry;
}

Expand All @@ -581,7 +582,7 @@ public boolean engineIsKeyEntry(String alias) {
*/
public boolean engineIsCertificateEntry(String alias) {
permissionCheck();
Object entry = entries.get(alias.toLowerCase());
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
return entry instanceof TrustedCertEntry;
}

Expand Down Expand Up @@ -806,18 +807,18 @@ private void createTrustedCertEntry(String alias, List<String> inputTrust,
// Check whether a certificate with same alias already exists and is the same
// If yes, we can return here - the existing entry must have the same
// properties and trust settings
if (entries.contains(alias.toLowerCase())) {
if (entries.contains(alias.toLowerCase(Locale.ROOT))) {
int uniqueVal = 1;
String originalAlias = alias;
var co = entries.get(alias.toLowerCase());
var co = entries.get(alias.toLowerCase(Locale.ROOT));
while (co != null) {
if (co instanceof TrustedCertEntry tco) {
if (tco.cert.equals(tce.cert)) {
return;
}
}
alias = originalAlias + " " + uniqueVal++;
co = entries.get(alias.toLowerCase());
co = entries.get(alias.toLowerCase(Locale.ROOT));
}
}

Expand Down Expand Up @@ -900,7 +901,7 @@ private void createTrustedCertEntry(String alias, List<String> inputTrust,
else
tce.date = new Date();

entries.put(alias.toLowerCase(), tce);
entries.put(alias.toLowerCase(Locale.ROOT), tce);
} catch (Exception e) {
// The certificate will be skipped.
System.err.println("KeychainStore Ignored Exception: " + e);
Expand Down Expand Up @@ -971,12 +972,12 @@ private void createKeyEntry(String alias, long creationDate, long secKeyRef,
int uniqueVal = 1;
String originalAlias = alias;

while (entries.containsKey(alias.toLowerCase())) {
while (entries.containsKey(alias.toLowerCase(Locale.ROOT))) {
alias = originalAlias + " " + uniqueVal;
uniqueVal++;
}

entries.put(alias.toLowerCase(), ke);
entries.put(alias.toLowerCase(Locale.ROOT), ke);
}

private static class CertKeychainItemPair {
Expand Down
6 changes: 4 additions & 2 deletions src/java.base/share/classes/java/net/ProxySelector.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,6 +27,8 @@

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import sun.security.util.SecurityConstants;

/**
Expand Down Expand Up @@ -210,7 +212,7 @@ public void connectFailed(URI uri, SocketAddress sa, IOException e) {

@Override
public synchronized List<Proxy> select(URI uri) {
String scheme = uri.getScheme().toLowerCase();
String scheme = uri.getScheme().toLowerCase(Locale.ROOT);
if (scheme.equals("http") || scheme.equals("https")) {
return list;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/security/KeyStore.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -817,7 +817,7 @@ protected KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type)
this.type = type;

if (!skipDebug && pdebug != null) {
pdebug.println("KeyStore." + type.toUpperCase() + " type from: " +
pdebug.println("KeyStore." + type.toUpperCase(Locale.ROOT) + " type from: " +
getProviderName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4725,7 +4725,7 @@ public int parse(DateTimeParseContext context, CharSequence text, int position)
* @return the position after the parse
*/
private int parseOffsetBased(DateTimeParseContext context, CharSequence text, int prefixPos, int position, OffsetIdPrinterParser parser) {
String prefix = text.subSequence(prefixPos, position).toString().toUpperCase();
String prefix = text.subSequence(prefixPos, position).toString().toUpperCase(Locale.ROOT);
if (position >= text.length()) {
context.setParsed(ZoneId.of(prefix));
return position;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,6 +32,7 @@
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import jdk.internal.org.xml.sax.InputSource;
import jdk.internal.org.xml.sax.SAXException;
Expand Down Expand Up @@ -1601,7 +1602,7 @@ private void pi() throws Exception {
// PI target name may not be empty string [#2.6]
// PI target name 'XML' is reserved [#2.6]
if ((str.isEmpty())
|| (mXml.name.equals(str.toLowerCase()) == true)) {
|| (mXml.name.equals(str.toLowerCase(Locale.ROOT)) == true)) {
panic(FAULT);
}
// This is processing instruction
Expand Down Expand Up @@ -2858,7 +2859,7 @@ protected void setinp(InputSource is)
String expenc;
if (is.getEncoding() != null) {
// Ignore encoding in the xml text decl.
expenc = is.getEncoding().toUpperCase();
expenc = is.getEncoding().toUpperCase(Locale.ROOT);
if (expenc.equals("UTF-16")) {
reader = bom(is.getByteStream(), 'U'); // UTF-16 [#4.3.3]
} else {
Expand Down Expand Up @@ -3156,7 +3157,7 @@ private String xml(Reader reader)
case 'A':
case '_':
bkch();
str = name(false).toLowerCase();
str = name(false).toLowerCase(Locale.ROOT);
if ("version".equals(str) == true) {
if (st != 1) {
panic(FAULT);
Expand All @@ -3170,15 +3171,15 @@ private String xml(Reader reader)
if (st != 2) {
panic(FAULT);
}
mInp.xmlenc = eqstr('=').toUpperCase();
mInp.xmlenc = eqstr('=').toUpperCase(Locale.ROOT);
enc = mInp.xmlenc;
st = 3;
} else if ("standalone".equals(str) == true) {
if ((st == 1) || (mPh >= PH_DOC_START)) // [#4.3.1]
{
panic(FAULT);
}
str = eqstr('=').toLowerCase();
str = eqstr('=').toLowerCase(Locale.ROOT);
// Check the 'standalone' value and use it [#5.1]
if (str.equals("yes") == true) {
mIsSAlone = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ public int compare(ModuleReference a, ModuleReference b) {
}

private static <T> Stream<String> toStringStream(Set<T> s) {
return s.stream().map(e -> e.toString().toLowerCase());
return s.stream().map(e -> e.toString().toLowerCase(Locale.ROOT));
}

private static boolean isJrt(ModuleReference mref) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ static Pattern toPattern(String mask) {
if (disjunct.isEmpty())
continue;
disjunctionEmpty = false;
String regex = disjunctToRegex(disjunct.toLowerCase());
String regex = disjunctToRegex(disjunct.toLowerCase(Locale.ROOT));
joiner.add(regex);
}
return disjunctionEmpty ? null : Pattern.compile(joiner.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.net.URL;
import java.security.GeneralSecurityException;
import java.util.Base64;
import java.util.Locale;
import java.util.Objects;
import java.util.Properties;

Expand Down Expand Up @@ -149,7 +150,7 @@ private void init (PasswordAuthentication pw) {
username = s;
ntdomain = defaultDomain;
} else {
ntdomain = s.substring (0, i).toUpperCase();
ntdomain = s.substring (0, i).toUpperCase(Locale.ROOT);
username = s.substring (i+1);
}
password = pw.getPassword();
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/unix/classes/sun/nio/fs/UnixFileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public Properties run() {
if (value != null) {
String[] values = value.split("\\s");
for (String s: values) {
s = s.trim().toLowerCase();
s = s.trim().toLowerCase(Locale.ROOT);
if (s.equals(feature)) {
return FeatureStatus.PRESENT;
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/windows/classes/java/lang/ProcessImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -393,7 +393,7 @@ private boolean isExe(String executablePath) {

// Old version that can be bypassed
private boolean isShellFile(String executablePath) {
String upPath = executablePath.toUpperCase();
String upPath = executablePath.toUpperCase(Locale.ROOT);
return (upPath.endsWith(".CMD") || upPath.endsWith(".BAT"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.net.PasswordAuthentication;
import java.net.UnknownHostException;
import java.net.URL;
import java.util.Locale;
import java.util.Objects;
import java.util.Properties;
import sun.net.NetProperties;
Expand Down Expand Up @@ -95,7 +96,7 @@ private void init0() {
public String run() {
String localhost;
try {
localhost = InetAddress.getLocalHost().getHostName().toUpperCase();
localhost = InetAddress.getLocalHost().getHostName().toUpperCase(Locale.ROOT);
} catch (UnknownHostException e) {
localhost = "localhost";
}
Expand Down Expand Up @@ -136,7 +137,7 @@ private void init (PasswordAuthentication pw) {
username = s;
ntdomain = defaultDomain;
} else {
ntdomain = s.substring (0, i).toUpperCase();
ntdomain = s.substring (0, i).toUpperCase(Locale.ROOT);
username = s.substring (i+1);
}
password = new String (pw.getPassword());
Expand Down

3 comments on commit b32d641

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JesperIRL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/tag jdk-22+11

@openjdk
Copy link

@openjdk openjdk bot commented on b32d641 Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JesperIRL The tag jdk-22+11 was successfully created.

Please sign in to comment.