8274318: Replace 'for' cycles with iterator with enhanced-for in java.management

Reviewed-by: cjplummer, sspitsyn, dfuchs
This commit is contained in:
Andrey Turbanov 2021-10-06 18:23:46 +00:00 committed by Daniel Fuchs
parent 754bc82c4c
commit 9945f7a074
3 changed files with 9 additions and 19 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2021, 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
@ -494,8 +494,7 @@ public abstract class RMIServerImpl implements Closeable, RMIServer {
if (subject != null) { if (subject != null) {
Set<Principal> principals = subject.getPrincipals(); Set<Principal> principals = subject.getPrincipals();
String sep = ""; String sep = "";
for (Iterator<Principal> it = principals.iterator(); it.hasNext(); ) { for (Principal p : principals) {
Principal p = it.next();
String name = p.getName().replace(' ', '_').replace(';', ':'); String name = p.getName().replace(' ', '_').replace(';', ':');
buf.append(sep).append(name); buf.append(sep).append(name);
sep = ";"; sep = ";";

View file

@ -33,7 +33,6 @@ import java.security.Principal;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
@ -314,8 +313,7 @@ public class MBeanServerFileAccessController
if (s == null) return; /* security has not been enabled */ if (s == null) return; /* security has not been enabled */
final Set<Principal> principals = s.getPrincipals(); final Set<Principal> principals = s.getPrincipals();
String newPropertyValue = null; String newPropertyValue = null;
for (Iterator<Principal> i = principals.iterator(); i.hasNext(); ) { for (Principal p : principals) {
final Principal p = i.next();
Access access = accessMap.get(p.getName()); Access access = accessMap.get(p.getName());
if (access != null) { if (access != null) {
boolean ok; boolean ok;

View file

@ -35,7 +35,6 @@ import java.io.ObjectStreamField;
import java.io.Serializable; import java.io.Serializable;
import java.security.AccessController; import java.security.AccessController;
import java.util.Iterator;
/** /**
* Represents the result of a multiple access to several roles of a relation * Represents the result of a multiple access to several roles of a relation
@ -132,7 +131,6 @@ public class RoleResult implements Serializable {
setRoles(list); setRoles(list);
setRolesUnresolved(unresolvedList); setRolesUnresolved(unresolvedList);
return;
} }
// //
@ -173,15 +171,13 @@ public class RoleResult implements Serializable {
roleList = new RoleList(); roleList = new RoleList();
for (Iterator<?> roleIter = list.iterator(); for (Object o : list) {
roleIter.hasNext();) { Role currRole = (Role)o;
Role currRole = (Role)(roleIter.next()); roleList.add((Role)currRole.clone());
roleList.add((Role)(currRole.clone()));
} }
} else { } else {
roleList = null; roleList = null;
} }
return;
} }
/** /**
@ -196,16 +192,13 @@ public class RoleResult implements Serializable {
unresolvedRoleList = new RoleUnresolvedList(); unresolvedRoleList = new RoleUnresolvedList();
for (Iterator<?> roleUnresIter = unresolvedList.iterator(); for (Object o : unresolvedList) {
roleUnresIter.hasNext();) { RoleUnresolved currRoleUnres = (RoleUnresolved)o;
RoleUnresolved currRoleUnres = unresolvedRoleList.add((RoleUnresolved)currRoleUnres.clone());
(RoleUnresolved)(roleUnresIter.next());
unresolvedRoleList.add((RoleUnresolved)(currRoleUnres.clone()));
} }
} else { } else {
unresolvedRoleList = null; unresolvedRoleList = null;
} }
return;
} }
/** /**