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

@ -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");
}