Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8297683: Use enhanced-for cycle instead of Enumeration in java.securi…
…ty.jgss

Reviewed-by: weijun
  • Loading branch information
Andrey Turbanov committed Dec 4, 2022
1 parent c67166f commit 0edb5d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
Expand Up @@ -134,10 +134,7 @@ void init(GSSManagerImpl gssManager) {

public void dispose() throws GSSException {
if (!destroyed) {
GSSCredentialSpi element;
Enumeration<GSSCredentialSpi> values = hashtable.elements();
while (values.hasMoreElements()) {
element = values.nextElement();
for (GSSCredentialSpi element : hashtable.values()) {
element.dispose();
}
destroyed = true;
Expand Down Expand Up @@ -211,14 +208,11 @@ public int getRemainingLifetime() throws GSSException {
"no longer valid");
}

SearchKey tempKey;
GSSCredentialSpi tempCred;
int tempLife, tempInitLife, tempAcceptLife;
int min = INDEFINITE_LIFETIME;

for (Enumeration<SearchKey> e = hashtable.keys();
e.hasMoreElements(); ) {
tempKey = e.nextElement();
for (SearchKey tempKey : hashtable.keySet()) {
tempCred = hashtable.get(tempKey);
if (tempKey.getUsage() == INITIATE_ONLY)
tempLife = tempCred.getInitLifetime();
Expand Down Expand Up @@ -329,13 +323,10 @@ public int getUsage() throws GSSException {
"no longer valid");
}

SearchKey tempKey;
boolean initiate = false;
boolean accept = false;

for (Enumeration<SearchKey> e = hashtable.keys();
e.hasMoreElements(); ) {
tempKey = e.nextElement();
for (SearchKey tempKey : hashtable.keySet()) {
if (tempKey.getUsage() == INITIATE_ONLY)
initiate = true;
else if (tempKey.getUsage() == ACCEPT_ONLY)
Expand Down Expand Up @@ -406,10 +397,7 @@ public Oid[] getMechs() throws GSSException {
"no longer valid");
}
ArrayList<Oid> result = new ArrayList<Oid>(hashtable.size());

for (Enumeration<SearchKey> e = hashtable.keys();
e.hasMoreElements(); ) {
SearchKey tempKey = e.nextElement();
for (SearchKey tempKey : hashtable.keySet()) {
result.add(tempKey.getMech());
}
return result.toArray(new Oid[0]);
Expand Down Expand Up @@ -615,14 +603,7 @@ public GSSCredentialSpi getElement(Oid mechOid, boolean initiate)
}

Set<GSSCredentialSpi> getElements() {
HashSet<GSSCredentialSpi> retVal =
new HashSet<>(hashtable.size());
Enumeration<GSSCredentialSpi> values = hashtable.elements();
while (values.hasMoreElements()) {
GSSCredentialSpi o = values.nextElement();
retVal.add(o);
}
return retVal;
return new HashSet<>(hashtable.values());
}

private static String getElementStr(Oid mechOid, int usage) {
Expand Down
Expand Up @@ -32,7 +32,6 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Enumeration;
import java.util.Iterator;
import sun.security.jgss.spi.*;
import sun.security.jgss.wrapper.NativeGSSFactory;
Expand Down Expand Up @@ -408,12 +407,9 @@ private boolean addAllMechsFromProvider(Provider p) {
String prop;
boolean retVal = false;

// Get all props for this provider
Enumeration<Object> props = p.keys();

// See if there are any GSS prop's
while (props.hasMoreElements()) {
prop = (String) props.nextElement();
for (Object o : p.keySet()) {
prop = (String) o;
if (isMechFactoryProperty(prop)) {
// Ok! This is a GSS provider!
try {
Expand All @@ -428,7 +424,7 @@ private boolean addAllMechsFromProvider(Provider p) {
}
}
} // Processed GSS property
} // while loop
} // for loop

return retVal;

Expand Down

1 comment on commit 0edb5d0

@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.