8274237: Replace 'for' cycles with iterator with enhanced-for in java.base

Reviewed-by: dfuchs, weijun
This commit is contained in:
Andrey Turbanov 2021-09-24 16:46:52 +00:00 committed by Weijun Wang
parent 0c050be64b
commit baafa6059e
4 changed files with 18 additions and 32 deletions

View file

@ -622,8 +622,7 @@ public final class Security {
// For each selection criterion, remove providers
// which don't satisfy the criterion from the candidate set.
for (Iterator<String> ite = keySet.iterator(); ite.hasNext(); ) {
String key = ite.next();
for (String key : keySet) {
String value = filter.get(key);
LinkedHashSet<Provider> newCandidates = getAllQualifyingCandidates(key, value,

View file

@ -200,8 +200,8 @@ public class PKIXParameters implements CertPathParameters {
throw new InvalidAlgorithmParameterException("the trustAnchors " +
"parameter must be non-empty");
}
for (Iterator<TrustAnchor> i = trustAnchors.iterator(); i.hasNext(); ) {
if (!(i.next() instanceof TrustAnchor)) {
for (Object trustAnchor : trustAnchors) {
if (!(trustAnchor instanceof TrustAnchor)) {
throw new ClassCastException("all elements of set must be "
+ "of type java.security.cert.TrustAnchor");
}
@ -249,9 +249,8 @@ public class PKIXParameters implements CertPathParameters {
*/
public void setInitialPolicies(Set<String> initialPolicies) {
if (initialPolicies != null) {
for (Iterator<String> i = initialPolicies.iterator();
i.hasNext();) {
if (!(i.next() instanceof String))
for (Object initialPolicy : initialPolicies) {
if (!(initialPolicy instanceof String))
throw new ClassCastException("all elements of set must be "
+ "of type java.lang.String");
}
@ -282,8 +281,8 @@ public class PKIXParameters implements CertPathParameters {
if (stores == null) {
this.certStores = new ArrayList<>();
} else {
for (Iterator<CertStore> i = stores.iterator(); i.hasNext();) {
if (!(i.next() instanceof CertStore)) {
for (Object store : stores) {
if (!(store instanceof CertStore)) {
throw new ClassCastException("all elements of list must be "
+ "of type java.security.cert.CertStore");
}

View file

@ -364,8 +364,7 @@ public class X509CRLSelector implements CRLSelector {
private static HashSet<X500Principal> parseIssuerNames(Collection<Object> names)
throws IOException {
HashSet<X500Principal> x500Principals = new HashSet<>();
for (Iterator<Object> t = names.iterator(); t.hasNext(); ) {
Object nameObject = t.next();
for (Object nameObject : names) {
if (nameObject instanceof String) {
x500Principals.add(new X500Name((String)nameObject).asX500Principal());
} else {