8311943: Cleanup usages of toLowerCase() and toUpperCase() in java.base

Reviewed-by: naoto
This commit is contained in:
Glavo 2023-08-16 17:37:21 +00:00 committed by Naoto Sato
parent 13f6450e2e
commit b32d6411c4
11 changed files with 44 additions and 38 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -181,7 +181,7 @@ public final class KeychainStore extends KeyStoreSpi {
password = Long.toString(random.nextLong()).toCharArray(); 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)) { if (!(entry instanceof KeyEntry keyEntry)) {
return null; return null;
@ -271,7 +271,7 @@ public final class KeychainStore extends KeyStoreSpi {
public Certificate[] engineGetCertificateChain(String alias) { public Certificate[] engineGetCertificateChain(String alias) {
permissionCheck(); permissionCheck();
Object entry = entries.get(alias.toLowerCase()); Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
if (entry instanceof KeyEntry keyEntry) { if (entry instanceof KeyEntry keyEntry) {
if (keyEntry.chain == null) { if (keyEntry.chain == null) {
@ -302,7 +302,7 @@ public final class KeychainStore extends KeyStoreSpi {
public Certificate engineGetCertificate(String alias) { public Certificate engineGetCertificate(String alias) {
permissionCheck(); permissionCheck();
Object entry = entries.get(alias.toLowerCase()); Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
if (entry != null) { if (entry != null) {
if (entry instanceof TrustedCertEntry) { if (entry instanceof TrustedCertEntry) {
@ -337,7 +337,7 @@ public final class KeychainStore extends KeyStoreSpi {
public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam) public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam)
throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException { throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException {
if (engineIsCertificateEntry(alias)) { if (engineIsCertificateEntry(alias)) {
Object entry = entries.get(alias.toLowerCase()); Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
if (entry instanceof TrustedCertEntry tEntry) { if (entry instanceof TrustedCertEntry tEntry) {
return new KeyStore.TrustedCertificateEntry( return new KeyStore.TrustedCertificateEntry(
tEntry.cert, Set.of( tEntry.cert, Set.of(
@ -359,7 +359,7 @@ public final class KeychainStore extends KeyStoreSpi {
public Date engineGetCreationDate(String alias) { public Date engineGetCreationDate(String alias) {
permissionCheck(); permissionCheck();
Object entry = entries.get(alias.toLowerCase()); Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
if (entry != null) { if (entry != null) {
if (entry instanceof TrustedCertEntry) { if (entry instanceof TrustedCertEntry) {
@ -427,7 +427,7 @@ public final class KeychainStore extends KeyStoreSpi {
entry.chainRefs = new long[entry.chain.length]; entry.chainRefs = new long[entry.chain.length];
} }
String lowerAlias = alias.toLowerCase(); String lowerAlias = alias.toLowerCase(Locale.ROOT);
if (entries.get(lowerAlias) != null) { if (entries.get(lowerAlias) != null) {
deletedEntries.put(lowerAlias, entries.get(lowerAlias)); deletedEntries.put(lowerAlias, entries.get(lowerAlias));
} }
@ -491,7 +491,7 @@ public final class KeychainStore extends KeyStoreSpi {
entry.chainRefs = new long[entry.chain.length]; entry.chainRefs = new long[entry.chain.length];
} }
String lowerAlias = alias.toLowerCase(); String lowerAlias = alias.toLowerCase(Locale.ROOT);
if (entries.get(lowerAlias) != null) { if (entries.get(lowerAlias) != null) {
deletedEntries.put(lowerAlias, entries.get(alias)); deletedEntries.put(lowerAlias, entries.get(alias));
} }
@ -521,9 +521,10 @@ public final class KeychainStore extends KeyStoreSpi {
{ {
permissionCheck(); permissionCheck();
String lowerAlias = alias.toLowerCase(Locale.ROOT);
synchronized(entries) { synchronized(entries) {
Object entry = entries.remove(alias.toLowerCase()); Object entry = entries.remove(lowerAlias);
deletedEntries.put(alias.toLowerCase(), entry); deletedEntries.put(lowerAlias, entry);
} }
} }
@ -546,7 +547,7 @@ public final class KeychainStore extends KeyStoreSpi {
*/ */
public boolean engineContainsAlias(String alias) { public boolean engineContainsAlias(String alias) {
permissionCheck(); permissionCheck();
return entries.containsKey(alias.toLowerCase()); return entries.containsKey(alias.toLowerCase(Locale.ROOT));
} }
/** /**
@ -568,7 +569,7 @@ public final class KeychainStore extends KeyStoreSpi {
*/ */
public boolean engineIsKeyEntry(String alias) { public boolean engineIsKeyEntry(String alias) {
permissionCheck(); permissionCheck();
Object entry = entries.get(alias.toLowerCase()); Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
return entry instanceof KeyEntry; return entry instanceof KeyEntry;
} }
@ -581,7 +582,7 @@ public final class KeychainStore extends KeyStoreSpi {
*/ */
public boolean engineIsCertificateEntry(String alias) { public boolean engineIsCertificateEntry(String alias) {
permissionCheck(); permissionCheck();
Object entry = entries.get(alias.toLowerCase()); Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
return entry instanceof TrustedCertEntry; return entry instanceof TrustedCertEntry;
} }
@ -806,10 +807,10 @@ public final class KeychainStore extends KeyStoreSpi {
// Check whether a certificate with same alias already exists and is the same // 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 // If yes, we can return here - the existing entry must have the same
// properties and trust settings // properties and trust settings
if (entries.contains(alias.toLowerCase())) { if (entries.contains(alias.toLowerCase(Locale.ROOT))) {
int uniqueVal = 1; int uniqueVal = 1;
String originalAlias = alias; String originalAlias = alias;
var co = entries.get(alias.toLowerCase()); var co = entries.get(alias.toLowerCase(Locale.ROOT));
while (co != null) { while (co != null) {
if (co instanceof TrustedCertEntry tco) { if (co instanceof TrustedCertEntry tco) {
if (tco.cert.equals(tce.cert)) { if (tco.cert.equals(tce.cert)) {
@ -817,7 +818,7 @@ public final class KeychainStore extends KeyStoreSpi {
} }
} }
alias = originalAlias + " " + uniqueVal++; alias = originalAlias + " " + uniqueVal++;
co = entries.get(alias.toLowerCase()); co = entries.get(alias.toLowerCase(Locale.ROOT));
} }
} }
@ -900,7 +901,7 @@ public final class KeychainStore extends KeyStoreSpi {
else else
tce.date = new Date(); tce.date = new Date();
entries.put(alias.toLowerCase(), tce); entries.put(alias.toLowerCase(Locale.ROOT), tce);
} catch (Exception e) { } catch (Exception e) {
// The certificate will be skipped. // The certificate will be skipped.
System.err.println("KeychainStore Ignored Exception: " + e); System.err.println("KeychainStore Ignored Exception: " + e);
@ -971,12 +972,12 @@ public final class KeychainStore extends KeyStoreSpi {
int uniqueVal = 1; int uniqueVal = 1;
String originalAlias = alias; String originalAlias = alias;
while (entries.containsKey(alias.toLowerCase())) { while (entries.containsKey(alias.toLowerCase(Locale.ROOT))) {
alias = originalAlias + " " + uniqueVal; alias = originalAlias + " " + uniqueVal;
uniqueVal++; uniqueVal++;
} }
entries.put(alias.toLowerCase(), ke); entries.put(alias.toLowerCase(Locale.ROOT), ke);
} }
private static class CertKeychainItemPair { private static class CertKeychainItemPair {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,8 @@ package java.net;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Locale;
import sun.security.util.SecurityConstants; import sun.security.util.SecurityConstants;
/** /**
@ -210,7 +212,7 @@ public abstract class ProxySelector {
@Override @Override
public synchronized List<Proxy> select(URI uri) { 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")) { if (scheme.equals("http") || scheme.equals("https")) {
return list; return list;
} else { } else {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -817,7 +817,7 @@ public class KeyStore {
this.type = type; this.type = type;
if (!skipDebug && pdebug != null) { if (!skipDebug && pdebug != null) {
pdebug.println("KeyStore." + type.toUpperCase() + " type from: " + pdebug.println("KeyStore." + type.toUpperCase(Locale.ROOT) + " type from: " +
getProviderName()); getProviderName());
} }
} }

View File

@ -4725,7 +4725,7 @@ public final class DateTimeFormatterBuilder {
* @return the position after the parse * @return the position after the parse
*/ */
private int parseOffsetBased(DateTimeParseContext context, CharSequence text, int prefixPos, int position, OffsetIdPrinterParser parser) { 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()) { if (position >= text.length()) {
context.setParsed(ZoneId.of(prefix)); context.setParsed(ZoneId.of(prefix));
return position; return position;

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -32,6 +32,7 @@ import java.io.Reader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import jdk.internal.org.xml.sax.InputSource; import jdk.internal.org.xml.sax.InputSource;
import jdk.internal.org.xml.sax.SAXException; import jdk.internal.org.xml.sax.SAXException;
@ -1601,7 +1602,7 @@ public abstract class Parser {
// PI target name may not be empty string [#2.6] // PI target name may not be empty string [#2.6]
// PI target name 'XML' is reserved [#2.6] // PI target name 'XML' is reserved [#2.6]
if ((str.isEmpty()) if ((str.isEmpty())
|| (mXml.name.equals(str.toLowerCase()) == true)) { || (mXml.name.equals(str.toLowerCase(Locale.ROOT)) == true)) {
panic(FAULT); panic(FAULT);
} }
// This is processing instruction // This is processing instruction
@ -2858,7 +2859,7 @@ public abstract class Parser {
String expenc; String expenc;
if (is.getEncoding() != null) { if (is.getEncoding() != null) {
// Ignore encoding in the xml text decl. // Ignore encoding in the xml text decl.
expenc = is.getEncoding().toUpperCase(); expenc = is.getEncoding().toUpperCase(Locale.ROOT);
if (expenc.equals("UTF-16")) { if (expenc.equals("UTF-16")) {
reader = bom(is.getByteStream(), 'U'); // UTF-16 [#4.3.3] reader = bom(is.getByteStream(), 'U'); // UTF-16 [#4.3.3]
} else { } else {
@ -3156,7 +3157,7 @@ public abstract class Parser {
case 'A': case 'A':
case '_': case '_':
bkch(); bkch();
str = name(false).toLowerCase(); str = name(false).toLowerCase(Locale.ROOT);
if ("version".equals(str) == true) { if ("version".equals(str) == true) {
if (st != 1) { if (st != 1) {
panic(FAULT); panic(FAULT);
@ -3170,7 +3171,7 @@ public abstract class Parser {
if (st != 2) { if (st != 2) {
panic(FAULT); panic(FAULT);
} }
mInp.xmlenc = eqstr('=').toUpperCase(); mInp.xmlenc = eqstr('=').toUpperCase(Locale.ROOT);
enc = mInp.xmlenc; enc = mInp.xmlenc;
st = 3; st = 3;
} else if ("standalone".equals(str) == true) { } else if ("standalone".equals(str) == true) {
@ -3178,7 +3179,7 @@ public abstract class Parser {
{ {
panic(FAULT); panic(FAULT);
} }
str = eqstr('=').toLowerCase(); str = eqstr('=').toLowerCase(Locale.ROOT);
// Check the 'standalone' value and use it [#5.1] // Check the 'standalone' value and use it [#5.1]
if (str.equals("yes") == true) { if (str.equals("yes") == true) {
mIsSAlone = true; mIsSAlone = true;

View File

@ -1315,7 +1315,7 @@ public final class LauncherHelper {
} }
private static <T> Stream<String> toStringStream(Set<T> s) { 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) { private static boolean isJrt(ModuleReference mref) {

View File

@ -377,7 +377,7 @@ public class DefaultProxySelector extends ProxySelector {
if (disjunct.isEmpty()) if (disjunct.isEmpty())
continue; continue;
disjunctionEmpty = false; disjunctionEmpty = false;
String regex = disjunctToRegex(disjunct.toLowerCase()); String regex = disjunctToRegex(disjunct.toLowerCase(Locale.ROOT));
joiner.add(regex); joiner.add(regex);
} }
return disjunctionEmpty ? null : Pattern.compile(joiner.toString()); return disjunctionEmpty ? null : Pattern.compile(joiner.toString());

View File

@ -34,6 +34,7 @@ import java.net.UnknownHostException;
import java.net.URL; import java.net.URL;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.Base64; import java.util.Base64;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.Properties; import java.util.Properties;
@ -149,7 +150,7 @@ public class NTLMAuthentication extends AuthenticationInfo {
username = s; username = s;
ntdomain = defaultDomain; ntdomain = defaultDomain;
} else { } else {
ntdomain = s.substring (0, i).toUpperCase(); ntdomain = s.substring (0, i).toUpperCase(Locale.ROOT);
username = s.substring (i+1); username = s.substring (i+1);
} }
password = pw.getPassword(); password = pw.getPassword();

View File

@ -288,7 +288,7 @@ abstract class UnixFileStore
if (value != null) { if (value != null) {
String[] values = value.split("\\s"); String[] values = value.split("\\s");
for (String s: values) { for (String s: values) {
s = s.trim().toLowerCase(); s = s.trim().toLowerCase(Locale.ROOT);
if (s.equals(feature)) { if (s.equals(feature)) {
return FeatureStatus.PRESENT; return FeatureStatus.PRESENT;
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -393,7 +393,7 @@ final class ProcessImpl extends Process {
// Old version that can be bypassed // Old version that can be bypassed
private boolean isShellFile(String executablePath) { private boolean isShellFile(String executablePath) {
String upPath = executablePath.toUpperCase(); String upPath = executablePath.toUpperCase(Locale.ROOT);
return (upPath.endsWith(".CMD") || upPath.endsWith(".BAT")); return (upPath.endsWith(".CMD") || upPath.endsWith(".BAT"));
} }

View File

@ -30,6 +30,7 @@ import java.net.InetAddress;
import java.net.PasswordAuthentication; import java.net.PasswordAuthentication;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.net.URL; import java.net.URL;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.Properties; import java.util.Properties;
import sun.net.NetProperties; import sun.net.NetProperties;
@ -95,7 +96,7 @@ public class NTLMAuthentication extends AuthenticationInfo {
public String run() { public String run() {
String localhost; String localhost;
try { try {
localhost = InetAddress.getLocalHost().getHostName().toUpperCase(); localhost = InetAddress.getLocalHost().getHostName().toUpperCase(Locale.ROOT);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
localhost = "localhost"; localhost = "localhost";
} }
@ -136,7 +137,7 @@ public class NTLMAuthentication extends AuthenticationInfo {
username = s; username = s;
ntdomain = defaultDomain; ntdomain = defaultDomain;
} else { } else {
ntdomain = s.substring (0, i).toUpperCase(); ntdomain = s.substring (0, i).toUpperCase(Locale.ROOT);
username = s.substring (i+1); username = s.substring (i+1);
} }
password = new String (pw.getPassword()); password = new String (pw.getPassword());