mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8274949: Use String.contains() instead of String.indexOf() in java.base
Reviewed-by: weijun, dfuchs, vtewari, lancea
This commit is contained in:
parent
09e8c8c64a
commit
6677554374
17 changed files with 35 additions and 38 deletions
|
@ -157,7 +157,7 @@ public class HttpCapture {
|
|||
if (p.matcher(s).find()) {
|
||||
String f = capFiles.get(i);
|
||||
File fi;
|
||||
if (f.indexOf("%d") >= 0) {
|
||||
if (f.contains("%d")) {
|
||||
java.util.Random rand = new java.util.Random();
|
||||
do {
|
||||
String f2 = f.replace("%d", Integer.toString(rand.nextInt()));
|
||||
|
|
|
@ -645,7 +645,7 @@ final class HttpsClient extends HttpClient
|
|||
// ignore
|
||||
}
|
||||
|
||||
if ((cipher != null) && (cipher.indexOf("_anon_") != -1)) {
|
||||
if ((cipher != null) && (cipher.contains("_anon_"))) {
|
||||
return;
|
||||
} else if ((hostnameVerifier != null) &&
|
||||
(hostnameVerifier.verify(host, session))) {
|
||||
|
|
|
@ -723,7 +723,7 @@ public class PolicyFile extends java.security.Policy {
|
|||
+ SELF;
|
||||
}
|
||||
// check for self
|
||||
if (pe.name != null && pe.name.indexOf(SELF) != -1) {
|
||||
if (pe.name != null && pe.name.contains(SELF)) {
|
||||
// Create a "SelfPermission" , it could be an
|
||||
// an unresolved permission which will be resolved
|
||||
// when implies is called
|
||||
|
|
|
@ -59,7 +59,7 @@ public class RSAPSSSignature extends SignatureSpi {
|
|||
private boolean isDigestEqual(String stdAlg, String givenAlg) {
|
||||
if (stdAlg == null || givenAlg == null) return false;
|
||||
|
||||
if (givenAlg.indexOf("-") != -1) {
|
||||
if (givenAlg.contains("-")) {
|
||||
return stdAlg.equalsIgnoreCase(givenAlg);
|
||||
} else {
|
||||
if (stdAlg.equals("SHA-1")) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2021, 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
|
||||
|
@ -25,7 +25,6 @@
|
|||
|
||||
package sun.security.rsa;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.*;
|
||||
import java.security.spec.*;
|
||||
import sun.security.util.ObjectIdentifier;
|
||||
|
@ -61,9 +60,9 @@ public class RSAUtil {
|
|||
|
||||
// match loosely in order to work with 3rd party providers which
|
||||
// may not follow the standard names
|
||||
if (name.indexOf("PSS") != -1) {
|
||||
if (name.contains("PSS")) {
|
||||
return PSS;
|
||||
} else if (name.indexOf("RSA") != -1) {
|
||||
} else if (name.contains("RSA")) {
|
||||
return RSA;
|
||||
} else { // no match
|
||||
throw new ProviderException("Unsupported algorithm " + name);
|
||||
|
@ -151,7 +150,7 @@ public class RSAUtil {
|
|||
} catch (ProviderException pe) {
|
||||
// accommodate RSA keys encoded with various RSA signature oids
|
||||
// for backward compatibility
|
||||
if (algName.indexOf("RSA") != -1) {
|
||||
if (algName.contains("RSA")) {
|
||||
result[0] = KeyType.RSA;
|
||||
} else {
|
||||
// pass it up
|
||||
|
|
|
@ -1473,10 +1473,10 @@ public final class Main {
|
|||
if (s == null) break;
|
||||
// OpenSSL does not use NEW
|
||||
//if (s.startsWith("-----BEGIN NEW CERTIFICATE REQUEST-----")) {
|
||||
if (s.startsWith("-----BEGIN") && s.indexOf("REQUEST") >= 0) {
|
||||
if (s.startsWith("-----BEGIN") && s.contains("REQUEST")) {
|
||||
canRead = true;
|
||||
//} else if (s.startsWith("-----END NEW CERTIFICATE REQUEST-----")) {
|
||||
} else if (s.startsWith("-----END") && s.indexOf("REQUEST") >= 0) {
|
||||
} else if (s.startsWith("-----END") && s.contains("REQUEST")) {
|
||||
break;
|
||||
} else if (canRead) {
|
||||
sb.append(s);
|
||||
|
|
|
@ -161,10 +161,10 @@ public class Debug {
|
|||
if (args == null)
|
||||
return false;
|
||||
else {
|
||||
if (args.indexOf("all") != -1)
|
||||
if (args.contains("all"))
|
||||
return true;
|
||||
else
|
||||
return (args.indexOf(option) != -1);
|
||||
return (args.contains(option));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class SignatureUtil {
|
|||
* form of an OID, or the OID value if no match is found.
|
||||
*/
|
||||
private static String checkName(String algName) {
|
||||
if (algName.indexOf(".") == -1) {
|
||||
if (!algName.contains(".")) {
|
||||
return algName;
|
||||
} else {
|
||||
// convert oid to String
|
||||
|
@ -100,7 +100,7 @@ public class SignatureUtil {
|
|||
// AlgorithmParameters.getAlgorithm() may returns oid if it's
|
||||
// created during DER decoding. Convert to use the standard name
|
||||
// before passing it to RSAUtil
|
||||
if (params.getAlgorithm().indexOf(".") != -1) {
|
||||
if (params.getAlgorithm().contains(".")) {
|
||||
try {
|
||||
params = createAlgorithmParameters(sigName,
|
||||
params.getEncoded());
|
||||
|
@ -109,9 +109,9 @@ public class SignatureUtil {
|
|||
}
|
||||
}
|
||||
|
||||
if (sigName.indexOf("RSA") != -1) {
|
||||
if (sigName.contains("RSA")) {
|
||||
paramSpec = RSAUtil.getParamSpec(params);
|
||||
} else if (sigName.indexOf("ECDSA") != -1) {
|
||||
} else if (sigName.contains("ECDSA")) {
|
||||
try {
|
||||
paramSpec = params.getParameterSpec(ECParameterSpec.class);
|
||||
} catch (Exception e) {
|
||||
|
@ -141,11 +141,11 @@ public class SignatureUtil {
|
|||
|
||||
if (paramBytes != null) {
|
||||
sigName = checkName(sigName).toUpperCase(Locale.ENGLISH);
|
||||
if (sigName.indexOf("RSA") != -1) {
|
||||
if (sigName.contains("RSA")) {
|
||||
AlgorithmParameters params =
|
||||
createAlgorithmParameters(sigName, paramBytes);
|
||||
paramSpec = RSAUtil.getParamSpec(params);
|
||||
} else if (sigName.indexOf("ECDSA") != -1) {
|
||||
} else if (sigName.contains("ECDSA")) {
|
||||
try {
|
||||
Provider p = Signature.getInstance(sigName).getProvider();
|
||||
paramSpec = ECUtil.getECParameterSpec(p, paramBytes);
|
||||
|
|
|
@ -520,7 +520,7 @@ public class AlgorithmId implements Serializable, DerEncoder {
|
|||
}
|
||||
|
||||
// unknown algorithm oids
|
||||
if (name.indexOf(".") == -1) {
|
||||
if (!name.contains(".")) {
|
||||
// see if there is a matching oid string alias mapping from
|
||||
// 3rd party providers
|
||||
name = name.toUpperCase(Locale.ENGLISH);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
|
@ -83,7 +83,7 @@ public final class LocaleMatcher {
|
|||
for (LanguageRange lr : priorityList) {
|
||||
String range = lr.getRange();
|
||||
if (range.startsWith("*-")
|
||||
|| range.indexOf("-*") != -1) { // Extended range
|
||||
|| range.contains("-*")) { // Extended range
|
||||
if (mode == AUTOSELECT_FILTERING) {
|
||||
return filterExtended(priorityList, tags);
|
||||
} else if (mode == MAP_EXTENDED_RANGES) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue