# HG changeset patch # User xuelei # Date 1528515340 25200 # Node ID a02692615745384cd13b2820ab100c620368e41d # Parent bad9f4c7eeec9e5e84a2fa5736351f3bf9214c12 code cleanup for SSLSessionContextImpl.java diff -r bad9f4c7eeec -r a02692615745 src/java.base/share/classes/sun/security/ssl/SSLSessionContextImpl.java --- a/src/java.base/share/classes/sun/security/ssl/SSLSessionContextImpl.java Fri Jun 08 19:43:11 2018 -0700 +++ b/src/java.base/share/classes/sun/security/ssl/SSLSessionContextImpl.java Fri Jun 08 20:35:40 2018 -0700 @@ -25,18 +25,19 @@ package sun.security.ssl; +import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.Locale; -import java.util.Vector; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSessionContext; import sun.security.util.Cache; final class SSLSessionContextImpl implements SSLSessionContext { - private Cache sessionCache; + private final Cache sessionCache; // session cache, session id as key - private Cache sessionHostPortCache; + private final Cache sessionHostPortCache; // session cache, "host:port" as key private int cacheLimit; // the max cache size private int timeout; // timeout in seconds @@ -134,7 +135,6 @@ return cacheLimit; } - // package-private method, used ONLY by ServerHandshaker SSLSessionImpl get(byte[] id) { return (SSLSessionImpl)getSession(id); @@ -158,7 +158,7 @@ return null; } - private String getKey(String hostname, int port) { + private static String getKey(String hostname, int port) { return (hostname + ":" + String.valueOf(port)).toLowerCase(Locale.ENGLISH); } @@ -189,29 +189,30 @@ if (s != null) { sessionCache.remove(key); sessionHostPortCache.remove( - getKey(s.getPeerHost(), s.getPeerPort())); + getKey(s.getPeerHost(), s.getPeerPort())); } } - private int getDefaultCacheLimit() { - int cacheLimit = 0; + private static int getDefaultCacheLimit() { + int defaultCacheLimit = 0; try { - String s = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - @Override - public String run() { - return System.getProperty( - "javax.net.ssl.sessionCacheSize"); - } - }); - cacheLimit = (s != null) ? Integer.valueOf(s).intValue() : 0; + String s = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + @Override + public String run() { + return System.getProperty( + "javax.net.ssl.sessionCacheSize"); + } + }); + defaultCacheLimit = (s != null) ? Integer.parseInt(s) : 0; } catch (Exception e) { + // swallow the exception } - return (cacheLimit > 0) ? cacheLimit : 0; + return (defaultCacheLimit > 0) ? defaultCacheLimit : 0; } - boolean isTimedout(SSLSession sess) { + private boolean isTimedout(SSLSession sess) { if (timeout == 0) { return false; } @@ -225,26 +226,26 @@ return false; } - final class SessionCacheVisitor + private final class SessionCacheVisitor implements Cache.CacheVisitor { - Vector ids = null; + ArrayList ids = null; // public void visit(java.util.Map map) {} @Override public void visit(java.util.Map map) { - ids = new Vector<>(map.size()); + ids = new ArrayList<>(map.size()); for (SessionId key : map.keySet()) { SSLSessionImpl value = map.get(key); if (!isTimedout(value)) { - ids.addElement(key.getId()); + ids.add(key.getId()); } } } - public Enumeration getSessionIds() { - return ids != null ? ids.elements() : - new Vector().elements(); + Enumeration getSessionIds() { + return ids != null ? Collections.enumeration(ids) : + Collections.emptyEnumeration(); } } }