Skip to content

Commit

Permalink
8295953: Use enhanced-for cycle instead of Enumeration in sun.security
Browse files Browse the repository at this point in the history
Reviewed-by: weijun
  • Loading branch information
Andrey Turbanov committed Nov 7, 2022
1 parent ba303c0 commit 3baad06
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ public boolean engineIsCertificateEntry(String alias) {
public String engineGetCertificateAlias(Certificate cert) {
Certificate certElem;

for (Enumeration<String> e = entries.keys(); e.hasMoreElements(); ) {
String alias = e.nextElement();
Object entry = entries.get(alias);
for (Map.Entry<String, Object> e : entries.entrySet()) {
String alias = e.getKey();
Object entry = e.getValue();
if (entry instanceof TrustedCertEntry) {
certElem = ((TrustedCertEntry)entry).cert;
} else if (((KeyEntry)entry).chain != null) {
Expand Down Expand Up @@ -566,10 +566,9 @@ public void engineStore(OutputStream stream, char[] password)

dos.writeInt(entries.size());

for (Enumeration<String> e = entries.keys(); e.hasMoreElements();) {

String alias = e.nextElement();
Object entry = entries.get(alias);
for (Map.Entry<String, Object> e : entries.entrySet()) {
String alias = e.getKey();
Object entry = e.getValue();

if (entry instanceof KeyEntry) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ public void write(Writer policy)
{
PrintWriter out = new PrintWriter(new BufferedWriter(policy));

Enumeration<GrantEntry> enum_ = grantElements();

out.println("/* AUTOMATICALLY GENERATED ON "+
(new java.util.Date()) + "*/");
out.println("/* DO NOT EDIT */");
Expand All @@ -333,8 +331,7 @@ public void write(Writer policy)
}

// write "grant" entries
while (enum_.hasMoreElements()) {
GrantEntry ge = enum_.nextElement();
for (GrantEntry ge : grantEntries) {
ge.write(out);
out.println();
}
Expand Down Expand Up @@ -938,9 +935,7 @@ public void write(PrintWriter out) {
}
}
out.println(" {");
Enumeration<PermissionEntry> enum_ = permissionEntries.elements();
while (enum_.hasMoreElements()) {
PermissionEntry pe = enum_.nextElement();
for (PermissionEntry pe : permissionEntries) {
out.write(" ");
pe.write(out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,9 +1311,7 @@ public void removeValue(String key) {
public String[] getValueNames() {
ArrayList<Object> v = new ArrayList<>();
Object securityCtx = SecureKey.getCurrentSecurityContext();
for (Enumeration<SecureKey> e = boundValues.keys();
e.hasMoreElements(); ) {
SecureKey key = e.nextElement();
for (SecureKey key : boundValues.keySet()) {
if (securityCtx.equals(key.getSecurityContext())) {
v.add(key.getAppKey());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4177,9 +4177,7 @@ private boolean buildChain(Pair<String,X509Certificate> certToVerify,
// Try out each certificate in the vector, until we find one
// whose public key verifies the signature of the certificate
// in question.
for (Enumeration<Pair<String,X509Certificate>> issuerCerts = vec.elements();
issuerCerts.hasMoreElements(); ) {
Pair<String,X509Certificate> issuerCert = issuerCerts.nextElement();
for (Pair<String, X509Certificate> issuerCert : vec) {
PublicKey issuerPubKey = issuerCert.snd.getPublicKey();
try {
certToVerify.snd.verify(issuerPubKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,8 @@ public byte[] getExtensionValue(String oid) {

if (extAlias == null) { // may be unknown
ObjectIdentifier findOID = ObjectIdentifier.of(oid);
Extension ex;
ObjectIdentifier inCertOID;
for (Enumeration<Extension> e = extensions.getElements();
e.hasMoreElements();) {
ex = e.nextElement();
inCertOID = ex.getExtensionId();
for (Extension ex : extensions.getAllExtensions()) {
ObjectIdentifier inCertOID = ex.getExtensionId();
if (inCertOID.equals(findOID)) {
crlExt = ex;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,12 +1014,8 @@ public byte[] getExtensionValue(String oid) {

if (extAlias == null) { // may be unknown
ObjectIdentifier findOID = ObjectIdentifier.of(oid);
Extension ex;
ObjectIdentifier inCertOID;
for (Enumeration<Extension> e = extensions.getElements();
e.hasMoreElements();) {
ex = e.nextElement();
inCertOID = ex.getExtensionId();
for (Extension ex : extensions.getAllExtensions()) {
ObjectIdentifier inCertOID = ex.getExtensionId();
if (inCertOID.equals(findOID)) {
crlExt = ex;
break;
Expand Down

1 comment on commit 3baad06

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.