Skip to content

Commit b32d641

Browse files
Glavonaotoj
authored andcommitted
8311943: Cleanup usages of toLowerCase() and toUpperCase() in java.base
Reviewed-by: naoto
1 parent 13f6450 commit b32d641

File tree

11 files changed

+44
-38
lines changed

11 files changed

+44
-38
lines changed

src/java.base/macosx/classes/apple/security/KeychainStore.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -181,7 +181,7 @@ public Key engineGetKey(String alias, char[] password)
181181
password = Long.toString(random.nextLong()).toCharArray();
182182
}
183183

184-
Object entry = entries.get(alias.toLowerCase());
184+
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
185185

186186
if (!(entry instanceof KeyEntry keyEntry)) {
187187
return null;
@@ -271,7 +271,7 @@ public Key engineGetKey(String alias, char[] password)
271271
public Certificate[] engineGetCertificateChain(String alias) {
272272
permissionCheck();
273273

274-
Object entry = entries.get(alias.toLowerCase());
274+
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
275275

276276
if (entry instanceof KeyEntry keyEntry) {
277277
if (keyEntry.chain == null) {
@@ -302,7 +302,7 @@ public Certificate[] engineGetCertificateChain(String alias) {
302302
public Certificate engineGetCertificate(String alias) {
303303
permissionCheck();
304304

305-
Object entry = entries.get(alias.toLowerCase());
305+
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
306306

307307
if (entry != null) {
308308
if (entry instanceof TrustedCertEntry) {
@@ -337,7 +337,7 @@ public String getValue() {
337337
public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam)
338338
throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException {
339339
if (engineIsCertificateEntry(alias)) {
340-
Object entry = entries.get(alias.toLowerCase());
340+
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
341341
if (entry instanceof TrustedCertEntry tEntry) {
342342
return new KeyStore.TrustedCertificateEntry(
343343
tEntry.cert, Set.of(
@@ -359,7 +359,7 @@ public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter
359359
public Date engineGetCreationDate(String alias) {
360360
permissionCheck();
361361

362-
Object entry = entries.get(alias.toLowerCase());
362+
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
363363

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

430-
String lowerAlias = alias.toLowerCase();
430+
String lowerAlias = alias.toLowerCase(Locale.ROOT);
431431
if (entries.get(lowerAlias) != null) {
432432
deletedEntries.put(lowerAlias, entries.get(lowerAlias));
433433
}
@@ -491,7 +491,7 @@ public void engineSetKeyEntry(String alias, byte[] key,
491491
entry.chainRefs = new long[entry.chain.length];
492492
}
493493

494-
String lowerAlias = alias.toLowerCase();
494+
String lowerAlias = alias.toLowerCase(Locale.ROOT);
495495
if (entries.get(lowerAlias) != null) {
496496
deletedEntries.put(lowerAlias, entries.get(alias));
497497
}
@@ -521,9 +521,10 @@ public void engineDeleteEntry(String alias)
521521
{
522522
permissionCheck();
523523

524+
String lowerAlias = alias.toLowerCase(Locale.ROOT);
524525
synchronized(entries) {
525-
Object entry = entries.remove(alias.toLowerCase());
526-
deletedEntries.put(alias.toLowerCase(), entry);
526+
Object entry = entries.remove(lowerAlias);
527+
deletedEntries.put(lowerAlias, entry);
527528
}
528529
}
529530

@@ -546,7 +547,7 @@ public Enumeration<String> engineAliases() {
546547
*/
547548
public boolean engineContainsAlias(String alias) {
548549
permissionCheck();
549-
return entries.containsKey(alias.toLowerCase());
550+
return entries.containsKey(alias.toLowerCase(Locale.ROOT));
550551
}
551552

552553
/**
@@ -568,7 +569,7 @@ public int engineSize() {
568569
*/
569570
public boolean engineIsKeyEntry(String alias) {
570571
permissionCheck();
571-
Object entry = entries.get(alias.toLowerCase());
572+
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
572573
return entry instanceof KeyEntry;
573574
}
574575

@@ -581,7 +582,7 @@ public boolean engineIsKeyEntry(String alias) {
581582
*/
582583
public boolean engineIsCertificateEntry(String alias) {
583584
permissionCheck();
584-
Object entry = entries.get(alias.toLowerCase());
585+
Object entry = entries.get(alias.toLowerCase(Locale.ROOT));
585586
return entry instanceof TrustedCertEntry;
586587
}
587588

@@ -806,18 +807,18 @@ private void createTrustedCertEntry(String alias, List<String> inputTrust,
806807
// Check whether a certificate with same alias already exists and is the same
807808
// If yes, we can return here - the existing entry must have the same
808809
// properties and trust settings
809-
if (entries.contains(alias.toLowerCase())) {
810+
if (entries.contains(alias.toLowerCase(Locale.ROOT))) {
810811
int uniqueVal = 1;
811812
String originalAlias = alias;
812-
var co = entries.get(alias.toLowerCase());
813+
var co = entries.get(alias.toLowerCase(Locale.ROOT));
813814
while (co != null) {
814815
if (co instanceof TrustedCertEntry tco) {
815816
if (tco.cert.equals(tce.cert)) {
816817
return;
817818
}
818819
}
819820
alias = originalAlias + " " + uniqueVal++;
820-
co = entries.get(alias.toLowerCase());
821+
co = entries.get(alias.toLowerCase(Locale.ROOT));
821822
}
822823
}
823824

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

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

974-
while (entries.containsKey(alias.toLowerCase())) {
975+
while (entries.containsKey(alias.toLowerCase(Locale.ROOT))) {
975976
alias = originalAlias + " " + uniqueVal;
976977
uniqueVal++;
977978
}
978979

979-
entries.put(alias.toLowerCase(), ke);
980+
entries.put(alias.toLowerCase(Locale.ROOT), ke);
980981
}
981982

982983
private static class CertKeychainItemPair {

src/java.base/share/classes/java/net/ProxySelector.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,8 @@
2727

2828
import java.io.IOException;
2929
import java.util.List;
30+
import java.util.Locale;
31+
3032
import sun.security.util.SecurityConstants;
3133

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

211213
@Override
212214
public synchronized List<Proxy> select(URI uri) {
213-
String scheme = uri.getScheme().toLowerCase();
215+
String scheme = uri.getScheme().toLowerCase(Locale.ROOT);
214216
if (scheme.equals("http") || scheme.equals("https")) {
215217
return list;
216218
} else {

src/java.base/share/classes/java/security/KeyStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -817,7 +817,7 @@ protected KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type)
817817
this.type = type;
818818

819819
if (!skipDebug && pdebug != null) {
820-
pdebug.println("KeyStore." + type.toUpperCase() + " type from: " +
820+
pdebug.println("KeyStore." + type.toUpperCase(Locale.ROOT) + " type from: " +
821821
getProviderName());
822822
}
823823
}

src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4725,7 +4725,7 @@ public int parse(DateTimeParseContext context, CharSequence text, int position)
47254725
* @return the position after the parse
47264726
*/
47274727
private int parseOffsetBased(DateTimeParseContext context, CharSequence text, int prefixPos, int position, OffsetIdPrinterParser parser) {
4728-
String prefix = text.subSequence(prefixPos, position).toString().toUpperCase();
4728+
String prefix = text.subSequence(prefixPos, position).toString().toUpperCase(Locale.ROOT);
47294729
if (position >= text.length()) {
47304730
context.setParsed(ZoneId.of(prefix));
47314731
return position;

src/java.base/share/classes/jdk/internal/util/xml/impl/Parser.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
3232
import java.io.UnsupportedEncodingException;
3333
import java.util.Arrays;
3434
import java.util.HashMap;
35+
import java.util.Locale;
3536
import java.util.Map;
3637
import jdk.internal.org.xml.sax.InputSource;
3738
import jdk.internal.org.xml.sax.SAXException;
@@ -1601,7 +1602,7 @@ private void pi() throws Exception {
16011602
// PI target name may not be empty string [#2.6]
16021603
// PI target name 'XML' is reserved [#2.6]
16031604
if ((str.isEmpty())
1604-
|| (mXml.name.equals(str.toLowerCase()) == true)) {
1605+
|| (mXml.name.equals(str.toLowerCase(Locale.ROOT)) == true)) {
16051606
panic(FAULT);
16061607
}
16071608
// This is processing instruction
@@ -2858,7 +2859,7 @@ protected void setinp(InputSource is)
28582859
String expenc;
28592860
if (is.getEncoding() != null) {
28602861
// Ignore encoding in the xml text decl.
2861-
expenc = is.getEncoding().toUpperCase();
2862+
expenc = is.getEncoding().toUpperCase(Locale.ROOT);
28622863
if (expenc.equals("UTF-16")) {
28632864
reader = bom(is.getByteStream(), 'U'); // UTF-16 [#4.3.3]
28642865
} else {
@@ -3156,7 +3157,7 @@ private String xml(Reader reader)
31563157
case 'A':
31573158
case '_':
31583159
bkch();
3159-
str = name(false).toLowerCase();
3160+
str = name(false).toLowerCase(Locale.ROOT);
31603161
if ("version".equals(str) == true) {
31613162
if (st != 1) {
31623163
panic(FAULT);
@@ -3170,15 +3171,15 @@ private String xml(Reader reader)
31703171
if (st != 2) {
31713172
panic(FAULT);
31723173
}
3173-
mInp.xmlenc = eqstr('=').toUpperCase();
3174+
mInp.xmlenc = eqstr('=').toUpperCase(Locale.ROOT);
31743175
enc = mInp.xmlenc;
31753176
st = 3;
31763177
} else if ("standalone".equals(str) == true) {
31773178
if ((st == 1) || (mPh >= PH_DOC_START)) // [#4.3.1]
31783179
{
31793180
panic(FAULT);
31803181
}
3181-
str = eqstr('=').toLowerCase();
3182+
str = eqstr('=').toLowerCase(Locale.ROOT);
31823183
// Check the 'standalone' value and use it [#5.1]
31833184
if (str.equals("yes") == true) {
31843185
mIsSAlone = true;

src/java.base/share/classes/sun/launcher/LauncherHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ public int compare(ModuleReference a, ModuleReference b) {
13151315
}
13161316

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

13211321
private static boolean isJrt(ModuleReference mref) {

src/java.base/share/classes/sun/net/spi/DefaultProxySelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static Pattern toPattern(String mask) {
377377
if (disjunct.isEmpty())
378378
continue;
379379
disjunctionEmpty = false;
380-
String regex = disjunctToRegex(disjunct.toLowerCase());
380+
String regex = disjunctToRegex(disjunct.toLowerCase(Locale.ROOT));
381381
joiner.add(regex);
382382
}
383383
return disjunctionEmpty ? null : Pattern.compile(joiner.toString());

src/java.base/unix/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.net.URL;
3535
import java.security.GeneralSecurityException;
3636
import java.util.Base64;
37+
import java.util.Locale;
3738
import java.util.Objects;
3839
import java.util.Properties;
3940

@@ -149,7 +150,7 @@ private void init (PasswordAuthentication pw) {
149150
username = s;
150151
ntdomain = defaultDomain;
151152
} else {
152-
ntdomain = s.substring (0, i).toUpperCase();
153+
ntdomain = s.substring (0, i).toUpperCase(Locale.ROOT);
153154
username = s.substring (i+1);
154155
}
155156
password = pw.getPassword();

src/java.base/unix/classes/sun/nio/fs/UnixFileStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public Properties run() {
288288
if (value != null) {
289289
String[] values = value.split("\\s");
290290
for (String s: values) {
291-
s = s.trim().toLowerCase();
291+
s = s.trim().toLowerCase(Locale.ROOT);
292292
if (s.equals(feature)) {
293293
return FeatureStatus.PRESENT;
294294
}

src/java.base/windows/classes/java/lang/ProcessImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1995, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -393,7 +393,7 @@ private boolean isExe(String executablePath) {
393393

394394
// Old version that can be bypassed
395395
private boolean isShellFile(String executablePath) {
396-
String upPath = executablePath.toUpperCase();
396+
String upPath = executablePath.toUpperCase(Locale.ROOT);
397397
return (upPath.endsWith(".CMD") || upPath.endsWith(".BAT"));
398398
}
399399

0 commit comments

Comments
 (0)