diff options
author | martin <none@none> | 2008-03-10 15:07:09 -0700 |
---|---|---|
committer | martin <none@none> | 2008-03-10 15:07:09 -0700 |
commit | cbc2edc7a946bf18b459ebf1fae69afda031b3e3 (patch) | |
tree | a21c1658e4ccfa792abe194177aebe7bd8c29733 /src/share/classes/sun | |
parent | 6eadddac51da90fca2e9e96bfdc121af15abe9f6 (diff) |
6600143: Remove another 450 unnecessary casts
Reviewed-by: alanb, iris, lmalvent, bristor, peterjones, darcy, wetmore
Diffstat (limited to 'src/share/classes/sun')
59 files changed, 471 insertions, 480 deletions
diff --git a/src/share/classes/sun/misc/ClassFileTransformer.java b/src/share/classes/sun/misc/ClassFileTransformer.java index a0d2c84ed..1d05f71cc 100644 --- a/src/share/classes/sun/misc/ClassFileTransformer.java +++ b/src/share/classes/sun/misc/ClassFileTransformer.java @@ -46,8 +46,10 @@ public abstract class ClassFileTransformer { // Singleton of ClassFileTransformer // - private static ArrayList transformerList = new ArrayList(); - private static Object[] transformers = new Object[0]; + private static ArrayList<ClassFileTransformer> transformerList + = new ArrayList<ClassFileTransformer>(); + private static ClassFileTransformer[] transformers + = new ClassFileTransformer[0]; /** * Add the class file transformer object. @@ -59,7 +61,7 @@ public abstract class ClassFileTransformer synchronized(transformerList) { transformerList.add(t); - transformers = transformerList.toArray(); + transformers = transformerList.toArray(new ClassFileTransformer[0]); } } @@ -68,7 +70,7 @@ public abstract class ClassFileTransformer * * @return ClassFileTransformer object array */ - public static Object[] getTransformers() + public static ClassFileTransformer[] getTransformers() { // transformers is not intended to be changed frequently, // so it is okay to not put synchronized block here diff --git a/src/share/classes/sun/misc/Cleaner.java b/src/share/classes/sun/misc/Cleaner.java index c6cd63697..036b6c94c 100644 --- a/src/share/classes/sun/misc/Cleaner.java +++ b/src/share/classes/sun/misc/Cleaner.java @@ -141,8 +141,8 @@ public class Cleaner try { thunk.run(); } catch (final Throwable x) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { if (System.err != null) new Error("Cleaner terminated abnormally", x) .printStackTrace(); diff --git a/src/share/classes/sun/misc/ExtensionDependency.java b/src/share/classes/sun/misc/ExtensionDependency.java index ce2df19f3..67012641e 100644 --- a/src/share/classes/sun/misc/ExtensionDependency.java +++ b/src/share/classes/sun/misc/ExtensionDependency.java @@ -284,10 +284,9 @@ public class ExtensionDependency { // Load the jar file ... Manifest man; try { - man = (Manifest) AccessController.doPrivileged - ( - new PrivilegedExceptionAction() { - public Object run() + man = AccessController.doPrivileged( + new PrivilegedExceptionAction<Manifest>() { + public Manifest run() throws IOException, FileNotFoundException { if (!file.exists()) throw new FileNotFoundException(file.getName()); @@ -391,9 +390,9 @@ public class ExtensionDependency { final String extName = extensionName; final String[] fileExt = {".jar", ".zip"}; - return (File) AccessController.doPrivileged - (new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction<File>() { + public File run() { try { File fExtension; File[] dirs = getExtDirs(); @@ -460,7 +459,7 @@ public class ExtensionDependency { * @return the list of files installed in all the directories */ private static File[] getExtFiles(File[] dirs) throws IOException { - Vector urls = new Vector(); + Vector<File> urls = new Vector<File>(); for (int i = 0; i < dirs.length; i++) { String[] files = dirs[i].list(new JarFilter()); if (files != null) { @@ -484,16 +483,15 @@ public class ExtensionDependency { * </p> */ private File[] getInstalledExtensions() throws IOException { - return (File[]) AccessController.doPrivileged - ( - new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction<File[]>() { + public File[] run() { try { return getExtFiles(getExtDirs()); } catch(IOException e) { debug("Cannot get list of installed extensions"); debugException(e); - return new URL[0]; + return new File[0]; } } }); diff --git a/src/share/classes/sun/misc/GC.java b/src/share/classes/sun/misc/GC.java index b3fd3f977..477b5ffad 100644 --- a/src/share/classes/sun/misc/GC.java +++ b/src/share/classes/sun/misc/GC.java @@ -128,8 +128,8 @@ public class GC { /* Create a new daemon thread in the root thread group */ public static void create() { - PrivilegedAction pa = new PrivilegedAction() { - public Object run() { + PrivilegedAction<Void> pa = new PrivilegedAction<Void>() { + public Void run() { ThreadGroup tg = Thread.currentThread().getThreadGroup(); for (ThreadGroup tgn = tg; tgn != null; @@ -170,13 +170,14 @@ public class GC { * method. Given a request, the only interesting operation is that of * cancellation. */ - public static class LatencyRequest implements Comparable { + public static class LatencyRequest + implements Comparable<LatencyRequest> { /* Instance counter, used to generate unique identifers */ private static long counter = 0; /* Sorted set of active latency requests */ - private static SortedSet requests = null; + private static SortedSet<LatencyRequest> requests = null; /* Examine the request set and reset the latency target if necessary. * Must be invoked while holding the lock. @@ -187,7 +188,7 @@ public class GC { setLatencyTarget(NO_TARGET); } } else { - LatencyRequest r = (LatencyRequest)requests.first(); + LatencyRequest r = requests.first(); if (r.latency != latencyTarget) { setLatencyTarget(r.latency); } @@ -211,7 +212,7 @@ public class GC { synchronized (lock) { this.id = ++counter; if (requests == null) { - requests = new TreeSet(); + requests = new TreeSet<LatencyRequest>(); } requests.add(this); adjustLatencyIfNeeded(); @@ -240,8 +241,7 @@ public class GC { } } - public int compareTo(Object o) { - LatencyRequest r = (LatencyRequest)o; + public int compareTo(LatencyRequest r) { long d = this.latency - r.latency; if (d == 0) d = this.id - r.id; return (d < 0) ? -1 : ((d > 0) ? +1 : 0); diff --git a/src/share/classes/sun/misc/Launcher.java b/src/share/classes/sun/misc/Launcher.java index fca660904..26f84d628 100644 --- a/src/share/classes/sun/misc/Launcher.java +++ b/src/share/classes/sun/misc/Launcher.java @@ -135,9 +135,9 @@ public class Launcher { // aa synthesized ACC via a call to the private method // ExtClassLoader.getContext(). - return (ExtClassLoader) AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Object run() throws IOException { + return AccessController.doPrivileged( + new PrivilegedExceptionAction<ExtClassLoader>() { + public ExtClassLoader run() throws IOException { int len = dirs.length; for (int i = 0; i < len; i++) { MetaIndex.registerDirectory(dirs[i]); @@ -180,7 +180,7 @@ public class Launcher { } private static URL[] getExtURLs(File[] dirs) throws IOException { - Vector urls = new Vector(); + Vector<URL> urls = new Vector<URL>(); for (int i = 0; i < dirs.length; i++) { String[] files = dirs[i].list(); if (files != null) { @@ -261,9 +261,9 @@ public class Launcher { // when loading classes. Specifically it prevent // accessClassInPackage.sun.* grants from being honored. // - return (AppClassLoader) - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction<AppClassLoader>() { + public AppClassLoader run() { URL[] urls = (s == null) ? new URL[0] : pathToURLs(path); return new AppClassLoader(urls, extcl); @@ -348,12 +348,12 @@ public class Launcher { URL[] urls; if (prop != null) { final String path = prop; - urls = (URL[])AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + urls = AccessController.doPrivileged( + new PrivilegedAction<URL[]>() { + public URL[] run() { File[] classPath = getClassPath(path); int len = classPath.length; - Set seenDirs = new HashSet(); + Set<File> seenDirs = new HashSet<File>(); for (int i = 0; i < len; i++) { File curEntry = classPath[i]; // Negative test used to properly handle @@ -509,8 +509,8 @@ class PathPermissions extends PermissionCollection { perms.add(new java.util.PropertyPermission("java.*", SecurityConstants.PROPERTY_READ_ACTION)); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { for (int i=0; i < path.length; i++) { File f = path[i]; String path; @@ -553,7 +553,7 @@ class PathPermissions extends PermissionCollection { return perms.implies(permission); } - public java.util.Enumeration elements() { + public java.util.Enumeration<Permission> elements() { if (perms == null) init(); synchronized (perms) { diff --git a/src/share/classes/sun/misc/PerformanceLogger.java b/src/share/classes/sun/misc/PerformanceLogger.java index 5f1218453..e23a0f1ab 100644 --- a/src/share/classes/sun/misc/PerformanceLogger.java +++ b/src/share/classes/sun/misc/PerformanceLogger.java @@ -78,7 +78,7 @@ public class PerformanceLogger { private static boolean perfLoggingOn = false; private static boolean useNanoTime = false; - private static Vector times; + private static Vector<TimeData> times; private static String logFileName = null; private static Writer logWriter = null; @@ -104,8 +104,8 @@ public class PerformanceLogger { if (logFileName != null) { if (logWriter == null) { java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { try { File logFile = new File(logFileName); logFile.createNewFile(); @@ -124,7 +124,7 @@ public class PerformanceLogger { logWriter = new OutputStreamWriter(System.out); } } - times = new Vector(10); + times = new Vector<TimeData>(10); // Reserve predefined slots for (int i = 0; i <= LAST_RESERVED; ++i) { times.add(new TimeData("Time " + i + " not set", 0)); @@ -207,7 +207,7 @@ public class PerformanceLogger { */ public static long getStartTime() { if (loggingEnabled()) { - return ((TimeData)times.get(START_INDEX)).getTime(); + return times.get(START_INDEX).getTime(); } else { return 0; } @@ -253,7 +253,7 @@ public class PerformanceLogger { */ public static long getTimeAtIndex(int index) { if (loggingEnabled()) { - return ((TimeData)times.get(index)).getTime(); + return times.get(index).getTime(); } else { return 0; } @@ -264,7 +264,7 @@ public class PerformanceLogger { */ public static String getMessageAtIndex(int index) { if (loggingEnabled()) { - return ((TimeData)times.get(index)).getMessage(); + return times.get(index).getMessage(); } else { return null; } @@ -278,7 +278,7 @@ public class PerformanceLogger { try { synchronized(times) { for (int i = 0; i < times.size(); ++i) { - TimeData td = (TimeData)times.get(i); + TimeData td = times.get(i); if (td != null) { writer.write(i + " " + td.getMessage() + ": " + td.getTime() + "\n"); diff --git a/src/share/classes/sun/misc/ProxyGenerator.java b/src/share/classes/sun/misc/ProxyGenerator.java index 42350461e..d25a87c1b 100644 --- a/src/share/classes/sun/misc/ProxyGenerator.java +++ b/src/share/classes/sun/misc/ProxyGenerator.java @@ -324,8 +324,8 @@ public class ProxyGenerator { if (saveGeneratedFiles) { java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { try { FileOutputStream file = new FileOutputStream(dotToSlash(name) + ".class"); @@ -576,7 +576,7 @@ public class ProxyGenerator { * compatibly with the throws clauses of both * overridden methods. */ - List<Class> legalExceptions = new ArrayList<Class>(); + List<Class<?>> legalExceptions = new ArrayList<Class<?>>(); collectCompatibleTypes( exceptionTypes, pm.exceptionTypes, legalExceptions); collectCompatibleTypes( @@ -618,11 +618,11 @@ public class ProxyGenerator { * List of return types that are not yet known to be * assignable from ("covered" by) any of the others. */ - LinkedList<Class> uncoveredReturnTypes = new LinkedList<Class>(); + LinkedList<Class<?>> uncoveredReturnTypes = new LinkedList<Class<?>>(); nextNewReturnType: for (ProxyMethod pm : methods) { - Class newReturnType = pm.returnType; + Class<?> newReturnType = pm.returnType; if (newReturnType.isPrimitive()) { throw new IllegalArgumentException( "methods with same signature " + @@ -637,9 +637,9 @@ public class ProxyGenerator { * Compare the new return type to the existing uncovered * return types. */ - ListIterator<Class> liter = uncoveredReturnTypes.listIterator(); + ListIterator<Class<?>> liter = uncoveredReturnTypes.listIterator(); while (liter.hasNext()) { - Class uncoveredReturnType = liter.next(); + Class<?> uncoveredReturnType = liter.next(); /* * If an existing uncovered return type is assignable @@ -944,10 +944,10 @@ public class ProxyGenerator { tryEnd = pc = (short) minfo.code.size(); - List<Class> catchList = computeUniqueCatchList(exceptionTypes); + List<Class<?>> catchList = computeUniqueCatchList(exceptionTypes); if (catchList.size() > 0) { - for (Class ex : catchList) { + for (Class<?> ex : catchList) { minfo.exceptionTable.add(new ExceptionTableEntry( tryBegin, tryEnd, pc, cp.getClass(dotToSlash(ex.getName())))); @@ -1521,8 +1521,9 @@ public class ProxyGenerator { * declared exceptions from duplicate methods inherited from * different interfaces. */ - private static void collectCompatibleTypes(Class[] from, Class[] with, - List<Class> list) + private static void collectCompatibleTypes(Class<?>[] from, + Class<?>[] with, + List<Class<?>> list) { for (int i = 0; i < from.length; i++) { if (!list.contains(from[i])) { @@ -1557,8 +1558,8 @@ public class ProxyGenerator { * given list of declared exceptions, indicating that no exceptions * need to be caught. */ - private static List<Class> computeUniqueCatchList(Class[] exceptions) { - List<Class> uniqueList = new ArrayList<Class>(); + private static List<Class<?>> computeUniqueCatchList(Class<?>[] exceptions) { + List<Class<?>> uniqueList = new ArrayList<Class<?>>(); // unique exceptions to catch uniqueList.add(Error.class); // always catch/rethrow these @@ -1566,7 +1567,7 @@ public class ProxyGenerator { nextException: for (int i = 0; i < exceptions.length; i++) { - Class ex = exceptions[i]; + Class<?> ex = exceptions[i]; if (ex.isAssignableFrom(Throwable.class)) { /* * If Throwable is declared to be thrown by the proxy method, @@ -1586,7 +1587,7 @@ public class ProxyGenerator { * exceptions that need to be caught: */ for (int j = 0; j < uniqueList.size();) { - Class ex2 = uniqueList.get(j); + Class<?> ex2 = uniqueList.get(j); if (ex2.isAssignableFrom(ex)) { /* * if a superclass of this exception is already on diff --git a/src/share/classes/sun/misc/URLClassPath.java b/src/share/classes/sun/misc/URLClassPath.java index 3aefe401d..b3bd6d38a 100644 --- a/src/share/classes/sun/misc/URLClassPath.java +++ b/src/share/classes/sun/misc/URLClassPath.java @@ -86,16 +86,16 @@ public class URLClassPath { } /* The original search path of URLs. */ - private ArrayList path = new ArrayList(); + private ArrayList<URL> path = new ArrayList<URL>(); /* The stack of unopened URLs */ - Stack urls = new Stack(); + Stack<URL> urls = new Stack<URL>(); /* The resulting search path of Loaders */ - ArrayList loaders = new ArrayList(); + ArrayList<Loader> loaders = new ArrayList<Loader>(); /* Map of each URL opened to its corresponding Loader */ - HashMap lmap = new HashMap(); + HashMap<URL, Loader> lmap = new HashMap<URL, Loader>(); /* The jar protocol handler to use when creating new URLs */ private URLStreamHandler jarHandler; @@ -146,7 +146,7 @@ public class URLClassPath { */ public URL[] getURLs() { synchronized (urls) { - return (URL[])path.toArray(new URL[path.size()]); + return path.toArray(new URL[path.size()]); } } @@ -200,9 +200,9 @@ public class URLClassPath { * @param name the resource name * @return an Enumeration of all the urls having the specified name */ - public Enumeration findResources(final String name, + public Enumeration<URL> findResources(final String name, final boolean check) { - return new Enumeration() { + return new Enumeration<URL>() { private int index = 0; private URL url = null; @@ -225,7 +225,7 @@ public class URLClassPath { return next(); } - public Object nextElement() { + public URL nextElement() { if (!next()) { throw new NoSuchElementException(); } @@ -247,9 +247,9 @@ public class URLClassPath { * @param name the resource name * @return an Enumeration of all the resources having the specified name */ - public Enumeration getResources(final String name, + public Enumeration<Resource> getResources(final String name, final boolean check) { - return new Enumeration() { + return new Enumeration<Resource>() { private int index = 0; private Resource res = null; @@ -272,7 +272,7 @@ public class URLClassPath { return next(); } - public Object nextElement() { + public Resource nextElement() { if (!next()) { throw new NoSuchElementException(); } @@ -283,7 +283,7 @@ public class URLClassPath { }; } - public Enumeration getResources(final String name) { + public Enumeration<Resource> getResources(final String name) { return getResources(name, true); } @@ -302,7 +302,7 @@ public class URLClassPath { if (urls.empty()) { return null; } else { - url = (URL)urls.pop(); + url = urls.pop(); } } // Skip this URL if it already has a Loader. (Loader @@ -329,7 +329,7 @@ public class URLClassPath { loaders.add(loader); lmap.put(url, loader); } - return (Loader)loaders.get(index); + return loaders.get(index); } /* @@ -337,9 +337,9 @@ public class URLClassPath { */ private Loader getLoader(final URL url) throws IOException { try { - return (Loader)java.security.AccessController.doPrivileged - (new java.security.PrivilegedExceptionAction() { - public Object run() throws IOException { + return java.security.AccessController.doPrivileged( + new java.security.PrivilegedExceptionAction<Loader>() { + public Loader run() throws IOException { String file = url.getFile(); if (file != null && file.endsWith("/")) { if ("file".equals(url.getProtocol())) { @@ -561,13 +561,14 @@ public class URLClassPath { private JarIndex index; private MetaIndex metaIndex; private URLStreamHandler handler; - private HashMap lmap; + private HashMap<URL, Loader> lmap; /* * Creates a new JarLoader for the specified URL referring to * a JAR file. */ - JarLoader(URL url, URLStreamHandler jarHandler, HashMap loaderMap) + JarLoader(URL url, URLStreamHandler jarHandler, + HashMap<URL, Loader> loaderMap) throws IOException { super(new URL("jar", "", -1, url + "!/", jarHandler)); @@ -615,8 +616,8 @@ public class URLClassPath { if (jar == null) { try { java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Object run() throws IOException { + new java.security.PrivilegedExceptionAction<Void>() { + public Void run() throws IOException { if (DEBUG) { System.err.println("Opening " + csu); Thread.dumpStack(); @@ -732,9 +733,9 @@ public class URLClassPath { String entryName; ZipEntry entry; - Enumeration enum_ = jar.entries(); + Enumeration<JarEntry> enum_ = jar.entries(); while (enum_.hasMoreElements()) { - entry = (ZipEntry)enum_.nextElement(); + entry = enum_.nextElement(); entryName = entry.getName(); if((pos = entryName.lastIndexOf("/")) != -1) entryName = entryName.substring(0, pos); @@ -778,7 +779,7 @@ public class URLClassPath { if (index == null) return null; - HashSet visited = new HashSet(); + HashSet<URL> visited = new HashSet<URL>(); return getResource(name, check, visited); } @@ -790,7 +791,7 @@ public class URLClassPath { * non-existent resource */ Resource getResource(final String name, boolean check, - Set visited) { + Set<URL> visited) { Resource res; Object[] jarFiles; @@ -819,10 +820,9 @@ public class URLClassPath { /* no loader has been set up for this jar file * before */ - newLoader = (JarLoader) - AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Object run() throws IOException { + newLoader = AccessController.doPrivileged( + new PrivilegedExceptionAction<JarLoader>() { + public JarLoader run() throws IOException { return new JarLoader(url, handler, lmap); } diff --git a/src/share/classes/sun/net/NetProperties.java b/src/share/classes/sun/net/NetProperties.java index c2c7eb54e..a94f20c2a 100644 --- a/src/share/classes/sun/net/NetProperties.java +++ b/src/share/classes/sun/net/NetProperties.java @@ -42,8 +42,8 @@ public class NetProperties { static private Properties props = new Properties(); static { AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + new PrivilegedAction<Void>() { + public Void run() { loadDefaultProperties(); return null; }}); diff --git a/src/share/classes/sun/net/NetworkClient.java b/src/share/classes/sun/net/NetworkClient.java index 6e49e4c30..321b71bf6 100644 --- a/src/share/classes/sun/net/NetworkClient.java +++ b/src/share/classes/sun/net/NetworkClient.java @@ -64,8 +64,8 @@ public class NetworkClient { final String encs[] = { null }; AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + new PrivilegedAction<Void>() { + public Void run() { vals[0] = Integer.getInteger("sun.net.client.defaultReadTimeout", 0).intValue(); vals[1] = Integer.getInteger("sun.net.client.defaultConnectTimeout", 0).intValue(); encs[0] = System.getProperty("file.encoding", "ISO8859_1"); @@ -152,9 +152,9 @@ public class NetworkClient { Socket s; if (proxy != null) { if (proxy.type() == Proxy.Type.SOCKS) { - s = (Socket) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + s = AccessController.doPrivileged( + new PrivilegedAction<Socket>() { + public Socket run() { return new Socket(proxy); }}); } else diff --git a/src/share/classes/sun/net/ftp/FtpClient.java b/src/share/classes/sun/net/ftp/FtpClient.java index 52458a688..9a7c99d51 100644 --- a/src/share/classes/sun/net/ftp/FtpClient.java +++ b/src/share/classes/sun/net/ftp/FtpClient.java @@ -117,8 +117,8 @@ public class FtpClient extends TransferProtocolClient { public static int getFtpProxyPort() { final int result[] = {80}; java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { String tmp = System.getProperty("ftp.proxyPort"); if (tmp == null) { @@ -343,9 +343,9 @@ public class FtpClient extends TransferProtocolClient { Socket s; if (proxy != null) { if (proxy.type() == Proxy.Type.SOCKS) { - s = (Socket) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + s = AccessController.doPrivileged( + new PrivilegedAction<Socket>() { + public Socket run() { return new Socket(proxy); }}); } else diff --git a/src/share/classes/sun/net/spi/DefaultProxySelector.java b/src/share/classes/sun/net/spi/DefaultProxySelector.java index 425c884fe..6d69c49bf 100644 --- a/src/share/classes/sun/net/spi/DefaultProxySelector.java +++ b/src/share/classes/sun/net/spi/DefaultProxySelector.java @@ -82,9 +82,9 @@ public class DefaultProxySelector extends ProxySelector { static { final String key = "java.net.useSystemProxies"; - Boolean b = (Boolean) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + Boolean b = AccessController.doPrivileged( + new PrivilegedAction<Boolean>() { + public Boolean run() { return NetProperties.getBoolean(key); }}); if (b != null && b.booleanValue()) { @@ -197,9 +197,9 @@ public class DefaultProxySelector extends ProxySelector { * System properties it does help having only 1 call to doPrivileged. * Be mindful what you do in here though! */ - Proxy p = (Proxy) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + Proxy p = AccessController.doPrivileged( + new PrivilegedAction<Proxy>() { + public Proxy run() { int i, j; String phost = null; int pport = 0; diff --git a/src/share/classes/sun/net/www/MessageHeader.java b/src/share/classes/sun/net/www/MessageHeader.java index 02fb42cd4..c02374d58 100644 --- a/src/share/classes/sun/net/www/MessageHeader.java +++ b/src/share/classes/sun/net/www/MessageHeader.java @@ -138,7 +138,7 @@ class MessageHeader { return null; } - class HeaderIterator implements Iterator { + class HeaderIterator implements Iterator<String> { int index = 0; int next = -1; String key; @@ -165,7 +165,7 @@ class MessageHeader { return false; } } - public Object next() { + public String next() { synchronized (lock) { if (haveNext) { haveNext = false; @@ -187,17 +187,17 @@ class MessageHeader { * return an Iterator that returns all values of a particular * key in sequence */ - public Iterator multiValueIterator (String k) { + public Iterator<String> multiValueIterator (String k) { return new HeaderIterator (k, this); } - public synchronized Map getHeaders() { + public synchronized Map<String, List<String>> getHeaders() { return getHeaders(null); } - public synchronized Map getHeaders(String[] excludeList) { + public synchronized Map<String, List<String>> getHeaders(String[] excludeList) { boolean skipIt = false; - Map m = new HashMap(); + Map<String, List<String>> m = new HashMap<String, List<String>>(); for (int i = nkeys; --i >= 0;) { if (excludeList != null) { // check if the key is in the excludeList. @@ -211,9 +211,9 @@ class MessageHeader { } } if (!skipIt) { - List l = (List)m.get(keys[i]); + List<String> l = m.get(keys[i]); if (l == null) { - l = new ArrayList(); + l = new ArrayList<String>(); m.put(keys[i], l); } l.add(values[i]); @@ -223,11 +223,8 @@ class MessageHeader { } } - Set keySet = m.keySet(); - for (Iterator i = keySet.iterator(); i.hasNext();) { - Object key = i.next(); - List l = (List)m.get(key); - m.put(key, Collections.unmodifiableList(l)); + for (String key : m.keySet()) { + m.put(key, Collections.unmodifiableList(m.get(key))); } return Collections.unmodifiableMap(m); diff --git a/src/share/classes/sun/net/www/MimeTable.java b/src/share/classes/sun/net/www/MimeTable.java index 291cf0586..6018fbf46 100644 --- a/src/share/classes/sun/net/www/MimeTable.java +++ b/src/share/classes/sun/net/www/MimeTable.java @@ -37,18 +37,20 @@ import java.util.StringTokenizer; public class MimeTable implements FileNameMap { /** Keyed by content type, returns MimeEntries */ - private Hashtable entries = new Hashtable(); + private Hashtable<String, MimeEntry> entries + = new Hashtable<String, MimeEntry>(); /** Keyed by file extension (with the .), returns MimeEntries */ - private Hashtable extensionMap = new Hashtable(); + private Hashtable<String, MimeEntry> extensionMap + = new Hashtable<String, MimeEntry>(); // Will be reset if in the platform-specific data file private static String tempFileTemplate; static { java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { tempFileTemplate = System.getProperty("content.types.temp.file.template", "/tmp/%s"); @@ -60,7 +62,8 @@ public class MimeTable implements FileNameMap { "/usr/etc/mailcap", "/usr/local/etc/mailcap", System.getProperty("hotjava.home", - "/usr/local/hotjava") + "/lib/mailcap", + "/usr/local/hotjava") + + "/lib/mailcap", }; return null; } @@ -83,8 +86,8 @@ public class MimeTable implements FileNameMap { public static MimeTable getDefaultTable() { if (defaultInstance == null) { java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { defaultInstance = new MimeTable(); URLConnection.setFileNameMap(defaultInstance); return null; @@ -130,7 +133,7 @@ public class MimeTable implements FileNameMap { } public synchronized MimeEntry remove(String type) { - MimeEntry entry = (MimeEntry)entries.get(type); + MimeEntry entry = entries.get(type); return remove(entry); } @@ -142,16 +145,16 @@ public class MimeTable implements FileNameMap { } } - return (MimeEntry)entries.remove(entry.getType()); + return entries.remove(entry.getType()); } public synchronized MimeEntry find(String type) { - MimeEntry entry = (MimeEntry)entries.get(type); + MimeEntry entry = entries.get(type); if (entry == null) { // try a wildcard lookup - Enumeration e = entries.elements(); + Enumeration<MimeEntry> e = entries.elements(); while (e.hasMoreElements()) { - MimeEntry wild = (MimeEntry)e.nextElement(); + MimeEntry wild = e.nextElement(); if (wild.matches(type)) { return wild; } @@ -191,13 +194,13 @@ public class MimeTable implements FileNameMap { * with it. */ public synchronized MimeEntry findByExt(String fileExtension) { - return (MimeEntry)extensionMap.get(fileExtension); + return extensionMap.get(fileExtension); } public synchronized MimeEntry findByDescription(String description) { - Enumeration e = elements(); + Enumeration<MimeEntry> e = elements(); while (e.hasMoreElements()) { - MimeEntry entry = (MimeEntry)e.nextElement(); + MimeEntry entry = e.nextElement(); if (description.equals(entry.getDescription())) { return entry; } @@ -211,7 +214,7 @@ public class MimeTable implements FileNameMap { return tempFileTemplate; } - public synchronized Enumeration elements() { + public synchronized Enumeration<MimeEntry> elements() { return entries.elements(); } @@ -269,7 +272,7 @@ public class MimeTable implements FileNameMap { } // now, parse the mime-type spec's - Enumeration types = entries.propertyNames(); + Enumeration<?> types = entries.propertyNames(); while (types.hasMoreElements()) { String type = (String)types.nextElement(); String attrs = entries.getProperty(type); @@ -392,9 +395,9 @@ public class MimeTable implements FileNameMap { public Properties getAsProperties() { Properties properties = new Properties(); - Enumeration e = elements(); + Enumeration<MimeEntry> e = elements(); while (e.hasMoreElements()) { - MimeEntry entry = (MimeEntry)e.nextElement(); + MimeEntry entry = e.nextElement(); properties.put(entry.getType(), entry.toProperty()); } diff --git a/src/share/classes/sun/net/www/http/HttpClient.java b/src/share/classes/sun/net/www/http/HttpClient.java index 674a88336..7f0cf0d42 100644 --- a/src/share/classes/sun/net/www/http/HttpClient.java +++ b/src/share/classes/sun/net/www/http/HttpClient.java @@ -230,9 +230,9 @@ public class HttpClient extends NetworkClient { setConnectTimeout(to); // get the cookieHandler if there is any - cookieHandler = (CookieHandler)java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + cookieHandler = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction<CookieHandler>() { + public CookieHandler run() { return CookieHandler.getDefault(); } }); @@ -297,7 +297,7 @@ public class HttpClient extends NetworkClient { HttpClient ret = null; /* see if one's already around */ if (useCache) { - ret = (HttpClient) kac.get(url, null); + ret = kac.get(url, null); if (ret != null) { if ((ret.proxy != null && ret.proxy.equals(p)) || (ret.proxy == null && p == null)) { @@ -389,7 +389,7 @@ public class HttpClient extends NetworkClient { * cache). */ public void closeIdleConnection() { - HttpClient http = (HttpClient) kac.get(url, null); + HttpClient http = kac.get(url, null); if (http != null) { http.closeServer(); } @@ -447,8 +447,8 @@ public class HttpClient extends NetworkClient { { try { java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Object run() throws IOException { + new java.security.PrivilegedExceptionAction<Void>() { + public Void run() throws IOException { openServer(server.getHostString(), server.getPort()); return null; } @@ -477,9 +477,8 @@ public class HttpClient extends NetworkClient { { try { java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Object run() throws IOException - { + new java.security.PrivilegedExceptionAction<Void>() { + public Void run() throws IOException { superOpenServer(proxyHost, proxyPort); return null; } @@ -686,7 +685,7 @@ public class HttpClient extends NetworkClient { // So we do put the cast in as a workaround until // it is resolved. if (uri != null) - cookieHandler.put(uri, (Map<java.lang.String,java.util.List<java.lang.String>>)responses.getHeaders()); + cookieHandler.put(uri, responses.getHeaders()); } /* decide if we're keeping alive: diff --git a/src/share/classes/sun/net/www/http/KeepAliveCache.java b/src/share/classes/sun/net/www/http/KeepAliveCache.java index 1226b2510..93882397a 100644 --- a/src/share/classes/sun/net/www/http/KeepAliveCache.java +++ b/src/share/classes/sun/net/www/http/KeepAliveCache.java @@ -38,7 +38,9 @@ import java.util.concurrent.ConcurrentHashMap; * @author Stephen R. Pietrowicz (NCSA) * @author Dave Brown */ -public class KeepAliveCache extends ConcurrentHashMap implements Runnable { +public class KeepAliveCache + extends ConcurrentHashMap<KeepAliveKey, ClientVector> + implements Runnable { private static final long serialVersionUID = -2937172892064557949L; /* maximum # keep-alive connections to maintain at once @@ -88,12 +90,12 @@ public class KeepAliveCache extends ConcurrentHashMap implements Runnable { * back from the server. If I'm connected through a Netscape proxy * to a server that sent me a keep-alive * time of 15 sec, the proxy unilaterally terminates my connection - * The robustness to to get around this is in HttpClient.parseHTTP() + * The robustness to get around this is in HttpClient.parseHTTP() */ final KeepAliveCache cache = this; java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { // We want to create the Keep-Alive-Timer in the // system threadgroup ThreadGroup grp = Thread.currentThread().getThreadGroup(); @@ -112,7 +114,7 @@ public class KeepAliveCache extends ConcurrentHashMap implements Runnable { } KeepAliveKey key = new KeepAliveKey(url, obj); - ClientVector v = (ClientVector)super.get(key); + ClientVector v = super.get(key); if (v == null) { int keepAliveTimeout = http.getKeepAliveTimeout(); @@ -125,10 +127,10 @@ public class KeepAliveCache extends ConcurrentHashMap implements Runnable { } } - /* remove an obsolete HttpClient from it's VectorCache */ + /* remove an obsolete HttpClient from its VectorCache */ public synchronized void remove (HttpClient h, Object obj) { KeepAliveKey key = new KeepAliveKey(h.url, obj); - ClientVector v = (ClientVector)super.get(key); + ClientVector v = super.get(key); if (v != null) { v.remove(h); if (v.empty()) { @@ -137,7 +139,7 @@ public class KeepAliveCache extends ConcurrentHashMap implements Runnable { } } - /* called by a clientVector thread when all it's connections have timed out + /* called by a clientVector thread when all its connections have timed out * and that vector of connections should be removed. */ synchronized void removeVector(KeepAliveKey k) { @@ -147,10 +149,10 @@ public class KeepAliveCache extends ConcurrentHashMap implements Runnable { /** * Check to see if this URL has a cached HttpClient */ - public synchronized Object get(URL url, Object obj) { + public synchronized HttpClient get(URL url, Object obj) { KeepAliveKey key = new KeepAliveKey(url, obj); - ClientVector v = (ClientVector)super.get(key); + ClientVector v = super.get(key); if (v == null) { // nothing in cache yet return null; } @@ -180,17 +182,16 @@ public class KeepAliveCache extends ConcurrentHashMap implements Runnable { long currentTime = System.currentTimeMillis(); - Iterator itr = keySet().iterator(); - ArrayList keysToRemove = new ArrayList(); + ArrayList<KeepAliveKey> keysToRemove + = new ArrayList<KeepAliveKey>(); - while (itr.hasNext()) { - KeepAliveKey key = (KeepAliveKey)itr.next(); - ClientVector v = (ClientVector)get(key); + for (KeepAliveKey key : keySet()) { + ClientVector v = get(key); synchronized (v) { int i; for (i = 0; i < v.size(); i++) { - KeepAliveEntry e = (KeepAliveEntry)v.elementAt(i); + KeepAliveEntry e = v.elementAt(i); if ((currentTime - e.idleStartTime) > v.nap) { HttpClient h = e.hc; h.closeServer(); @@ -205,9 +206,9 @@ public class KeepAliveCache extends ConcurrentHashMap implements Runnable { } } } - itr = keysToRemove.iterator(); - while (itr.hasNext()) { - removeVector((KeepAliveKey)itr.next()); + + for (KeepAliveKey key : keysToRemove) { + removeVector(key); } } } while (size() > 0); @@ -234,7 +235,7 @@ public class KeepAliveCache extends ConcurrentHashMap implements Runnable { */ -class ClientVector extends java.util.Stack { +class ClientVector extends java.util.Stack<KeepAliveEntry> { private static final long serialVersionUID = -8680532108106489459L; // sleep time in milliseconds, before cache clear @@ -254,7 +255,7 @@ class ClientVector extends java.util.Stack { HttpClient hc = null; long currentTime = System.currentTimeMillis(); do { - KeepAliveEntry e = (KeepAliveEntry)pop(); + KeepAliveEntry e = pop(); if ((currentTime - e.idleStartTime) > nap) { e.hc.closeServer(); } else { diff --git a/src/share/classes/sun/net/www/http/KeepAliveStream.java b/src/share/classes/sun/net/www/http/KeepAliveStream.java index 779afb5ad..08fc3b03b 100644 --- a/src/share/classes/sun/net/www/http/KeepAliveStream.java +++ b/src/share/classes/sun/net/www/http/KeepAliveStream.java @@ -174,8 +174,8 @@ class KeepAliveStream extends MeteredStream implements Hurryable { if (startCleanupThread) { java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { // We want to create the Keep-Alive-SocketCleaner in the // system threadgroup ThreadGroup grp = Thread.currentThread().getThreadGroup(); diff --git a/src/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java b/src/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java index 779e38ac9..3ae7cff0f 100644 --- a/src/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java +++ b/src/share/classes/sun/net/www/http/KeepAliveStreamCleaner.java @@ -59,19 +59,19 @@ public class KeepAliveStreamCleaner extends LinkedBlockingQueue<KeepAliveCleaner static { final String maxDataKey = "http.KeepAlive.remainingData"; - int maxData = ((Integer) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - return new Integer(NetProperties.getInteger(maxDataKey, MAX_DATA_REMAINING)); - }})).intValue() * 1024; + int maxData = AccessController.doPrivileged( + new PrivilegedAction<Integer>() { + public Integer run() { + return NetProperties.getInteger(maxDataKey, MAX_DATA_REMAINING); + }}).intValue() * 1024; MAX_DATA_REMAINING = maxData; final String maxCapacityKey = "http.KeepAlive.queuedConnections"; - int maxCapacity = ((Integer) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { - return new Integer(NetProperties.getInteger(maxCapacityKey, MAX_CAPACITY)); - }})).intValue(); + int maxCapacity = AccessController.doPrivileged( + new PrivilegedAction<Integer>() { + public Integer run() { + return NetProperties.getInteger(maxCapacityKey, MAX_CAPACITY); + }}).intValue(); MAX_CAPACITY = maxCapacity; } diff --git a/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java b/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java index 44473d421..3661090f8 100644 --- a/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java +++ b/src/share/classes/sun/net/www/protocol/ftp/FtpURLConnection.java @@ -215,12 +215,11 @@ public class FtpURLConnection extends URLConnection { Proxy p = null; if (instProxy == null) { // no per connection proxy specified /** - * Do we have to use a proxie? + * Do we have to use a proxy? */ - ProxySelector sel = (ProxySelector) - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + ProxySelector sel = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction<ProxySelector>() { + public ProxySelector run() { return ProxySelector.getDefault(); } }); diff --git a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java index fb1f3b05e..af0bd046f 100644 --- a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java +++ b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java @@ -144,8 +144,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { static { maxRedirects = java.security.AccessController.doPrivileged( - new sun.security.action.GetIntegerAction("http.maxRedirects", - defaultmaxRedirects)).intValue(); + new sun.security.action.GetIntegerAction( + "http.maxRedirects", defaultmaxRedirects)).intValue(); version = java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("java.version")); String agent = java.security.AccessController.doPrivileged( @@ -291,10 +291,9 @@ public class HttpURLConnection extends java.net.HttpURLConnection { final String scheme, final URL url, final RequestorType authType) { - return (PasswordAuthentication) - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + return java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction<PasswordAuthentication>() { + public PasswordAuthentication run() { return Authenticator.requestPasswordAuthentication( host, addr, port, protocol, prompt, scheme, url, authType); @@ -559,15 +558,15 @@ public class HttpURLConnection extends java.net.HttpURLConnection { responses = new MessageHeader(); this.handler = handler; instProxy = p; - cookieHandler = (CookieHandler)java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + cookieHandler = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction<CookieHandler>() { + public CookieHandler run() { return CookieHandler.getDefault(); } }); - cacheHandler = (ResponseCache)java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + cacheHandler = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction<ResponseCache>() { + public ResponseCache run() { return ResponseCache.getDefault(); } }); @@ -650,8 +649,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { final boolean result[] = {false}; java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { try { InetAddress a1 = InetAddress.getByName(h1); InetAddress a2 = InetAddress.getByName(h2); @@ -729,10 +728,10 @@ public class HttpURLConnection extends java.net.HttpURLConnection { /** * Do we have to use a proxy? */ - ProxySelector sel = (ProxySelector) + ProxySelector sel = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<ProxySelector>() { + public ProxySelector run() { return ProxySelector.getDefault(); } }); @@ -908,25 +907,23 @@ public class HttpURLConnection extends java.net.HttpURLConnection { URI uri = ParseUtil.toURI(url); if (uri != null) { - Map cookies = cookieHandler.get(uri, requests.getHeaders(EXCLUDE_HEADERS)); + Map<String, List<String>> cookies + = cookieHandler.get( + uri, requests.getHeaders(EXCLUDE_HEADERS)); if (!cookies.isEmpty()) { - Set s = cookies.entrySet(); - Iterator k_itr = s.iterator(); - while (k_itr.hasNext()) { - Map.Entry entry = (Map.Entry)k_itr.next(); - String key = (String)entry.getKey(); + for (Map.Entry<String, List<String>> entry : + cookies.entrySet()) { + String key = entry.getKey(); // ignore all entries that don't have "Cookie" // or "Cookie2" as keys if (!"Cookie".equalsIgnoreCase(key) && !"Cookie2".equalsIgnoreCase(key)) { continue; } - List l = (List)entry.getValue(); + List<String> l = entry.getValue(); if (l != null && !l.isEmpty()) { - Iterator v_itr = l.iterator(); StringBuilder cookieValue = new StringBuilder(); - while (v_itr.hasNext()) { - String value = (String)v_itr.next(); + for (String value : l) { cookieValue.append(value).append(';'); } // strip off the ending ;-sign @@ -1363,23 +1360,20 @@ public class HttpURLConnection extends java.net.HttpURLConnection { * original exception and with the same message. Right now, * there is no convenient APIs for doing so. */ - private IOException getChainedException(IOException rememberedException) { + private IOException getChainedException(final IOException rememberedException) { try { - final IOException originalException = rememberedException; - final Class[] cls = new Class[1]; - cls[0] = String.class; - final String[] args = new String[1]; - args[0] = originalException.getMessage(); - IOException chainedException = (IOException) - java.security.AccessController.doPrivileged - (new java.security.PrivilegedExceptionAction() { - public Object run() - throws Exception { - Constructor ctr = originalException.getClass().getConstructor(cls); - return (IOException)ctr.newInstance((Object[])args); + final Object[] args = { rememberedException.getMessage() }; + IOException chainedException = + java.security.AccessController.doPrivileged( + new java.security.PrivilegedExceptionAction<IOException>() { + public IOException run() throws Exception { + return (IOException) + rememberedException.getClass() + .getConstructor(new Class[] { String.class }) + .newInstance(args); } }); - chainedException.initCause(originalException); + chainedException.initCause(rememberedException); return chainedException; } catch (Exception ignored) { return rememberedException; @@ -1629,10 +1623,9 @@ public class HttpURLConnection extends java.net.HttpURLConnection { InetAddress addr = null; try { final String finalHost = host; - addr = (InetAddress) - java.security.AccessController.doPrivileged - (new java.security.PrivilegedExceptionAction() { - public Object run() + addr = java.security.AccessController.doPrivileged( + new java.security.PrivilegedExceptionAction<InetAddress>() { + public InetAddress run() throws java.net.UnknownHostException { return InetAddress.getByName(finalHost); } @@ -2174,7 +2167,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { * @return a Map of header fields * @since 1.4 */ - public Map getHeaderFields() { + public Map<String, List<String>> getHeaderFields() { try { getInputStream(); } catch (IOException e) {} @@ -2286,7 +2279,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { * @throws IllegalStateException if already connected * @since 1.4 */ - public Map getRequestProperties() { + public Map<String, List<String>> getRequestProperties() { if (connected) throw new IllegalStateException("Already connected"); @@ -2367,20 +2360,15 @@ public class HttpURLConnection extends java.net.HttpURLConnection { return method; } - private MessageHeader mapToMessageHeader(Map map) { + private MessageHeader mapToMessageHeader(Map<String, List<String>> map) { MessageHeader headers = new MessageHeader(); if (map == null || map.isEmpty()) { return headers; } - Set entries = map.entrySet(); - Iterator itr1 = entries.iterator(); - while (itr1.hasNext()) { - Map.Entry entry = (Map.Entry)itr1.next(); - String key = (String)entry.getKey(); - List values = (List)entry.getValue(); - Iterator itr2 = values.iterator(); - while (itr2.hasNext()) { - String value = (String)itr2.next(); + for (Map.Entry<String, List<String>> entry : map.entrySet()) { + String key = entry.getKey(); + List<String> values = entry.getValue(); + for (String value : values) { if (key == null) { headers.prepend(key, value); } else { diff --git a/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java b/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java index 4388f79d8..80b9f0f76 100644 --- a/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java +++ b/src/share/classes/sun/net/www/protocol/jar/URLJarFile.java @@ -55,7 +55,7 @@ public class URLJarFile extends JarFile { private Manifest superMan; private Attributes superAttr; - private Map superEntries; + private Map<String, Attributes> superEntries; static JarFile getJarFile(URL url) throws IOException { return getJarFile(url, null); @@ -146,12 +146,10 @@ public class URLJarFile extends JarFile { // now deep copy the manifest entries if (superEntries != null) { - Map entries = man.getEntries(); - Iterator it = superEntries.keySet().iterator(); - while (it.hasNext()) { - Object key = it.next(); - Attributes at = (Attributes)superEntries.get(key); - entries.put(key, at.clone()); + Map<String, Attributes> entries = man.getEntries(); + for (String key : superEntries.keySet()) { + Attributes at = superEntries.get(key); + entries.put(key, (Attributes) at.clone()); } } @@ -213,9 +211,9 @@ public class URLJarFile extends JarFile { final InputStream in = url.openConnection().getInputStream(); try { - result = (JarFile) - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws IOException { + result = AccessController.doPrivileged( + new PrivilegedExceptionAction<JarFile>() { + public JarFile run() throws IOException { OutputStream out = null; File tmpFile = null; try { @@ -273,9 +271,9 @@ public class URLJarFile extends JarFile { public Attributes getAttributes() throws IOException { if (URLJarFile.this.isSuperMan()) { - Map e = URLJarFile.this.superEntries; + Map<String, Attributes> e = URLJarFile.this.superEntries; if (e != null) { - Attributes a = (Attributes)e.get(getName()); + Attributes a = e.get(getName()); if (a != null) return (Attributes)a.clone(); } diff --git a/src/share/classes/sun/nio/ch/Reflect.java b/src/share/classes/sun/nio/ch/Reflect.java index b50c600e3..cd98bf8df 100644 --- a/src/share/classes/sun/nio/ch/Reflect.java +++ b/src/share/classes/sun/nio/ch/Reflect.java @@ -43,8 +43,8 @@ class Reflect { // package-private } private static void setAccessible(final AccessibleObject ao) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { ao.setAccessible(true); return null; }}); @@ -54,7 +54,7 @@ class Reflect { // package-private Class[] paramTypes) { try { - Class cl = Class.forName(className); + Class<?> cl = Class.forName(className); Constructor c = cl.getDeclaredConstructor(paramTypes); setAccessible(c); return c; @@ -82,7 +82,7 @@ class Reflect { // package-private Class[] paramTypes) { try { - Class cl = Class.forName(className); + Class<?> cl = Class.forName(className); Method m = cl.getDeclaredMethod(methodName, paramTypes); setAccessible(m); return m; diff --git a/src/share/classes/sun/nio/ch/SocketAdaptor.java b/src/share/classes/sun/nio/ch/SocketAdaptor.java index e852204d8..d8c26a2d1 100644 --- a/src/share/classes/sun/nio/ch/SocketAdaptor.java +++ b/src/share/classes/sun/nio/ch/SocketAdaptor.java @@ -242,9 +242,9 @@ public class SocketAdaptor throw new SocketException("Socket input is shutdown"); if (socketInputStream == null) { try { - socketInputStream = (InputStream)AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Object run() throws IOException { + socketInputStream = AccessController.doPrivileged( + new PrivilegedExceptionAction<InputStream>() { + public InputStream run() throws IOException { return new SocketInputStream(); } }); @@ -264,9 +264,9 @@ public class SocketAdaptor throw new SocketException("Socket output is shutdown"); OutputStream os = null; try { - os = (OutputStream) - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws IOException { + os = AccessController.doPrivileged( + new PrivilegedExceptionAction<OutputStream>() { + public OutputStream run() throws IOException { return Channels.newOutputStream(sc); } }); diff --git a/src/share/classes/sun/nio/ch/Util.java b/src/share/classes/sun/nio/ch/Util.java index bacaa59f8..73b66e072 100644 --- a/src/share/classes/sun/nio/ch/Util.java +++ b/src/share/classes/sun/nio/ch/Util.java @@ -49,20 +49,21 @@ class Util { private static final int TEMP_BUF_POOL_SIZE = 3; // Per-thread soft cache of the last temporary direct buffer - private static ThreadLocal[] bufferPool; + private static ThreadLocal<SoftReference<ByteBuffer>>[] bufferPool; static { - bufferPool = new ThreadLocal[TEMP_BUF_POOL_SIZE]; + bufferPool = (ThreadLocal<SoftReference<ByteBuffer>>[]) + new ThreadLocal[TEMP_BUF_POOL_SIZE]; for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) - bufferPool[i] = new ThreadLocal(); + bufferPool[i] = new ThreadLocal<SoftReference<ByteBuffer>>(); } static ByteBuffer getTemporaryDirectBuffer(int size) { ByteBuffer buf = null; // Grab a buffer if available for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) { - SoftReference ref = (SoftReference)(bufferPool[i].get()); - if ((ref != null) && ((buf = (ByteBuffer)ref.get()) != null) && + SoftReference<ByteBuffer> ref = bufferPool[i].get(); + if ((ref != null) && ((buf = ref.get()) != null) && (buf.capacity() >= size)) { buf.rewind(); buf.limit(size); @@ -80,18 +81,18 @@ class Util { return; // Put it in an empty slot if such exists for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) { - SoftReference ref = (SoftReference)(bufferPool[i].get()); + SoftReference<ByteBuffer> ref = bufferPool[i].get(); if ((ref == null) || (ref.get() == null)) { - bufferPool[i].set(new SoftReference(buf)); + bufferPool[i].set(new SoftReference<ByteBuffer>(buf)); return; } } // Otherwise replace a smaller one in the cache if such exists for (int i=0; i<TEMP_BUF_POOL_SIZE; i++) { - SoftReference ref = (SoftReference)(bufferPool[i].get()); - ByteBuffer inCacheBuf = (ByteBuffer)ref.get(); + SoftReference<ByteBuffer> ref = bufferPool[i].get(); + ByteBuffer inCacheBuf = ref.get(); if ((inCacheBuf == null) || (buf.capacity() > inCacheBuf.capacity())) { - bufferPool[i].set(new SoftReference(buf)); + bufferPool[i].set(new SoftReference<ByteBuffer>(buf)); return; } } @@ -120,10 +121,12 @@ class Util { } // Per-thread cached selector - private static ThreadLocal localSelector = new ThreadLocal(); + private static ThreadLocal<SoftReference<SelectorWrapper>> localSelector + = new ThreadLocal<SoftReference<SelectorWrapper>>(); // Hold a reference to the selWrapper object to prevent it from // being cleaned when the temporary selector wrapped is on lease. - private static ThreadLocal localSelectorWrapper = new ThreadLocal(); + private static ThreadLocal<SelectorWrapper> localSelectorWrapper + = new ThreadLocal<SelectorWrapper>(); // When finished, invoker must ensure that selector is empty // by cancelling any related keys and explicitly releasing @@ -131,15 +134,16 @@ class Util { static Selector getTemporarySelector(SelectableChannel sc) throws IOException { - SoftReference ref = (SoftReference)localSelector.get(); + SoftReference<SelectorWrapper> ref = localSelector.get(); SelectorWrapper selWrapper = null; Selector sel = null; if (ref == null - || ((selWrapper = (SelectorWrapper) ref.get()) == null) + || ((selWrapper = ref.get()) == null) || ((sel = selWrapper.get()) == null) || (sel.provider() != sc.provider())) { sel = sc.provider().openSelector(); - localSelector.set(new SoftReference(new SelectorWrapper(sel))); + localSelector.set(new SoftReference<SelectorWrapper>( + new SelectorWrapper(sel))); } else { localSelectorWrapper.set(selWrapper); } @@ -235,10 +239,10 @@ class Util { private static volatile Constructor directByteBufferConstructor = null; private static void initDBBConstructor() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { try { - Class cl = Class.forName("java.nio.DirectByteBuffer"); + Class<?> cl = Class.forName("java.nio.DirectByteBuffer"); Constructor ctor = cl.getDeclaredConstructor( new Class[] { int.class, long.class, @@ -282,10 +286,10 @@ class Util { private static volatile Constructor directByteBufferRConstructor = null; private static void initDBBRConstructor() { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { try { - Class cl = Class.forName("java.nio.DirectByteBufferR"); + Class<?> cl = Class.forName("java.nio.DirectByteBufferR"); Constructor ctor = cl.getDeclaredConstructor( new Class[] { int.class, long.class, diff --git a/src/share/classes/sun/reflect/ClassDefiner.java b/src/share/classes/sun/reflect/ClassDefiner.java index 63a4e2af4..91efcfffe 100644 --- a/src/share/classes/sun/reflect/ClassDefiner.java +++ b/src/share/classes/sun/reflect/ClassDefiner.java @@ -54,9 +54,9 @@ class ClassDefiner { static Class defineClass(String name, byte[] bytes, int off, int len, final ClassLoader parentClassLoader) { - ClassLoader newLoader = (ClassLoader) - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + ClassLoader newLoader = AccessController.doPrivileged( + new PrivilegedAction<ClassLoader>() { + public ClassLoader run() { return new DelegatingClassLoader(parentClassLoader); } }); diff --git a/src/share/classes/sun/reflect/MethodAccessorGenerator.java b/src/share/classes/sun/reflect/MethodAccessorGenerator.java index 3b62e2df8..fd72a6e1c 100644 --- a/src/share/classes/sun/reflect/MethodAccessorGenerator.java +++ b/src/share/classes/sun/reflect/MethodAccessorGenerator.java @@ -392,11 +392,12 @@ class MethodAccessorGenerator extends AccessorGenerator { // same namespace as the target class. Since the generated code // is privileged anyway, the protection domain probably doesn't // matter. - return (MagicAccessorImpl) - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction<MagicAccessorImpl>() { + public MagicAccessorImpl run() { try { - return ClassDefiner.defineClass + return (MagicAccessorImpl) + ClassDefiner.defineClass (generatedName, bytes, 0, diff --git a/src/share/classes/sun/reflect/ReflectionFactory.java b/src/share/classes/sun/reflect/ReflectionFactory.java index 30a1ac47c..54dc717f6 100644 --- a/src/share/classes/sun/reflect/ReflectionFactory.java +++ b/src/share/classes/sun/reflect/ReflectionFactory.java @@ -84,8 +84,8 @@ public class ReflectionFactory { * <code>AccessController.doPrivileged</code>. */ public static final class GetReflectionFactoryAction - implements PrivilegedAction { - public Object run() { + implements PrivilegedAction<ReflectionFactory> { + public ReflectionFactory run() { return getReflectionFactory(); } } @@ -164,7 +164,7 @@ public class ReflectionFactory { public ConstructorAccessor newConstructorAccessor(Constructor c) { checkInitted(); - Class declaringClass = c.getDeclaringClass(); + Class<?> declaringClass = c.getDeclaringClass(); if (Modifier.isAbstract(declaringClass.getModifiers())) { return new InstantiationExceptionConstructorAccessorImpl(null); } @@ -204,9 +204,9 @@ public class ReflectionFactory { /** Creates a new java.lang.reflect.Field. Access checks as per java.lang.reflect.AccessibleObject are not overridden. */ - public Field newField(Class declaringClass, + public Field newField(Class<?> declaringClass, String name, - Class type, + Class<?> type, int modifiers, int slot, String signature, @@ -223,11 +223,11 @@ public class ReflectionFactory { /** Creates a new java.lang.reflect.Method. Access checks as per java.lang.reflect.AccessibleObject are not overridden. */ - public Method newMethod(Class declaringClass, + public Method newMethod(Class<?> declaringClass, String name, - Class[] parameterTypes, - Class returnType, - Class[] checkedExceptions, + Class<?>[] parameterTypes, + Class<?> returnType, + Class<?>[] checkedExceptions, int modifiers, int slot, String signature, @@ -250,9 +250,9 @@ public class ReflectionFactory { /** Creates a new java.lang.reflect.Constructor. Access checks as per java.lang.reflect.AccessibleObject are not overridden. */ - public Constructor newConstructor(Class declaringClass, - Class[] parameterTypes, - Class[] checkedExceptions, + public Constructor newConstructor(Class<?> declaringClass, + Class<?>[] parameterTypes, + Class<?>[] checkedExceptions, int modifiers, int slot, String signature, @@ -310,7 +310,7 @@ public class ReflectionFactory { /** Makes a copy of the passed constructor. The returned constructor is a "child" of the passed one; see the comments in Constructor.java for details. */ - public Constructor copyConstructor(Constructor arg) { + public <T> Constructor<T> copyConstructor(Constructor<T> arg) { return langReflectAccess().copyConstructor(arg); } @@ -321,7 +321,7 @@ public class ReflectionFactory { // public Constructor newConstructorForSerialization - (Class classToInstantiate, Constructor constructorToCall) + (Class<?> classToInstantiate, Constructor constructorToCall) { // Fast path if (constructorToCall.getDeclaringClass() == classToInstantiate) { @@ -366,8 +366,9 @@ public class ReflectionFactory { run, before the system properties are set up. */ private static void checkInitted() { if (initted) return; - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged( + new PrivilegedAction<Void>() { + public Void run() { // Tests to ensure the system properties table is fully // initialized. This is needed because reflection code is // called very early in the initialization process (before diff --git a/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java b/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java index 45147dc51..56f1bad4b 100644 --- a/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java +++ b/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java @@ -273,8 +273,8 @@ class AnnotationInvocationHandler implements InvocationHandler, Serializable { private Method[] getMemberMethods() { if (memberMethods == null) { final Method[] mm = type.getDeclaredMethods(); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + public Void run() { AccessibleObject.setAccessible(mm, true); return null; } diff --git a/src/share/classes/sun/reflect/misc/MethodUtil.java b/src/share/classes/sun/reflect/misc/MethodUtil.java index b36993337..9c1bfbea4 100644 --- a/src/share/classes/sun/reflect/misc/MethodUtil.java +++ b/src/share/classes/sun/reflect/misc/MethodUtil.java @@ -67,7 +67,7 @@ public final class MethodUtil extends SecureClassLoader { super(); } - public static Method getMethod(Class cls, String name, Class[] args) + public static Method getMethod(Class<?> cls, String name, Class[] args) throws NoSuchMethodException { ReflectUtil.checkPackageAccess(cls); return cls.getMethod(name, args); @@ -89,7 +89,7 @@ public final class MethodUtil extends SecureClassLoader { if (System.getSecurityManager() == null) { return cls.getMethods(); } - Map sigs = new HashMap(); + Map<Signature, Method> sigs = new HashMap<Signature, Method>(); while (cls != null) { boolean done = getInternalPublicMethods(cls, sigs); if (done) { @@ -98,14 +98,14 @@ public final class MethodUtil extends SecureClassLoader { getInterfaceMethods(cls, sigs); cls = cls.getSuperclass(); } - Collection c = sigs.values(); - return (Method[]) c.toArray(new Method[c.size()]); + return sigs.values().toArray(new Method[sigs.size()]); } /* * Process the immediate interfaces of this class or interface. */ - private static void getInterfaceMethods(Class cls, Map sigs) { + private static void getInterfaceMethods(Class cls, + Map<Signature, Method> sigs) { Class[] intfs = cls.getInterfaces(); for (int i=0; i < intfs.length; i++) { Class intf = intfs[i]; @@ -120,7 +120,8 @@ public final class MethodUtil extends SecureClassLoader { * * Process the methods in this class or interface */ - private static boolean getInternalPublicMethods(Class cls, Map sigs) { + private static boolean getInternalPublicMethods(Class cls, + Map<Signature, Method> sigs) { Method[] methods = null; try { /* @@ -178,7 +179,7 @@ public final class MethodUtil extends SecureClassLoader { return done; } - private static void addMethod(Map sigs, Method method) { + private static void addMethod(Map<Signature, Method> sigs, Method method) { Signature signature = new Signature(method); if (!sigs.containsKey(signature)) { sigs.put(signature, method); @@ -186,7 +187,7 @@ public final class MethodUtil extends SecureClassLoader { /* * Superclasses beat interfaces. */ - Method old = (Method)sigs.get(signature); + Method old = sigs.get(signature); if (old.getDeclaringClass().isInterface()) { sigs.put(signature, method); } @@ -280,17 +281,15 @@ public final class MethodUtil extends SecureClassLoader { } private static Method getTrampoline() { - Method tramp = null; - try { - tramp = (Method) AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Class[] types; - Class t = getTrampolineClass(); - Method b; - - types = new Class[] {Method.class, Object.class, Object[].class}; - b = t.getDeclaredMethod("invoke", types); + return AccessController.doPrivileged( + new PrivilegedExceptionAction<Method>() { + public Method run() throws Exception { + Class<?> t = getTrampolineClass(); + Class[] types = { + Method.class, Object.class, Object[].class + }; + Method b = t.getDeclaredMethod("invoke", types); ((AccessibleObject)b).setAccessible(true); return b; } @@ -298,7 +297,6 @@ public final class MethodUtil extends SecureClassLoader { } catch (Exception e) { throw new InternalError("bouncer cannot be found"); } - return tramp; } diff --git a/src/share/classes/sun/rmi/log/ReliableLog.java b/src/share/classes/sun/rmi/log/ReliableLog.java index 7ac285819..542c6d27a 100644 --- a/src/share/classes/sun/rmi/log/ReliableLog.java +++ b/src/share/classes/sun/rmi/log/ReliableLog.java @@ -140,8 +140,8 @@ public class ReliableLog { throws IOException { super(); - this.Debug = ((Boolean) AccessController.doPrivileged( - new GetBooleanAction("sun.rmi.log.debug"))).booleanValue(); + this.Debug = AccessController.doPrivileged( + new GetBooleanAction("sun.rmi.log.debug")).booleanValue(); dir = new File(dirPath); if (!(dir.exists() && dir.isDirectory())) { // create directory @@ -333,8 +333,8 @@ public class ReliableLog { private static Constructor<? extends LogFile> getLogClassConstructor() { - String logClassName = ((String) AccessController.doPrivileged( - new GetPropertyAction("sun.rmi.log.class"))); + String logClassName = AccessController.doPrivileged( + new GetPropertyAction("sun.rmi.log.class")); if (logClassName != null) { try { ClassLoader loader = diff --git a/src/share/classes/sun/rmi/registry/RegistryImpl.java b/src/share/classes/sun/rmi/registry/RegistryImpl.java index 2f29cd570..7a99a014e 100644 --- a/src/share/classes/sun/rmi/registry/RegistryImpl.java +++ b/src/share/classes/sun/rmi/registry/RegistryImpl.java @@ -66,8 +66,10 @@ public class RegistryImpl extends java.rmi.server.RemoteServer /* indicate compatibility with JDK 1.1.x version of class */ private static final long serialVersionUID = 4666870661827494597L; - private Hashtable bindings = new Hashtable(101); - private static Hashtable allowedAccessCache = new Hashtable(3); + private Hashtable<String, Remote> bindings + = new Hashtable<String, Remote>(101); + private static Hashtable<InetAddress, InetAddress> allowedAccessCache + = new Hashtable<InetAddress, InetAddress>(3); private static RegistryImpl registry; private static ObjID id = new ObjID(ObjID.REGISTRY_ID); @@ -119,7 +121,7 @@ public class RegistryImpl extends java.rmi.server.RemoteServer throws RemoteException, NotBoundException { synchronized (bindings) { - Remote obj = (Remote)bindings.get(name); + Remote obj = bindings.get(name); if (obj == null) throw new NotBoundException(name); return obj; @@ -136,7 +138,7 @@ public class RegistryImpl extends java.rmi.server.RemoteServer { checkAccess("Registry.bind"); synchronized (bindings) { - Remote curr = (Remote)bindings.get(name); + Remote curr = bindings.get(name); if (curr != null) throw new AlreadyBoundException(name); bindings.put(name, obj); @@ -153,7 +155,7 @@ public class RegistryImpl extends java.rmi.server.RemoteServer { checkAccess("Registry.unbind"); synchronized (bindings) { - Remote obj = (Remote)bindings.get(name); + Remote obj = bindings.get(name); if (obj == null) throw new NotBoundException(name); bindings.remove(name); @@ -203,10 +205,9 @@ public class RegistryImpl extends java.rmi.server.RemoteServer InetAddress clientHost; try { - clientHost = (InetAddress) - java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Object run() + clientHost = java.security.AccessController.doPrivileged( + new java.security.PrivilegedExceptionAction<InetAddress>() { + public InetAddress run() throws java.net.UnknownHostException { return InetAddress.getByName(clientHostName); @@ -228,8 +229,8 @@ public class RegistryImpl extends java.rmi.server.RemoteServer final InetAddress finalClientHost = clientHost; java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Object run() throws java.io.IOException { + new java.security.PrivilegedExceptionAction<Void>() { + public Void run() throws java.io.IOException { /* * if a ServerSocket can be bound to the client's * address then that address must be local diff --git a/src/share/classes/sun/rmi/rmic/RemoteClass.java b/src/share/classes/sun/rmi/rmic/RemoteClass.java index 0caa07fe0..7d41be369 100644 --- a/src/share/classes/sun/rmi/rmic/RemoteClass.java +++ b/src/share/classes/sun/rmi/rmic/RemoteClass.java @@ -103,7 +103,7 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { * in the array). */ public ClassDefinition[] getRemoteInterfaces() { - return (ClassDefinition[]) remoteInterfaces.clone(); + return remoteInterfaces.clone(); } /** @@ -118,7 +118,7 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { * stub/skeleton protocol. */ public Method[] getRemoteMethods() { - return (Method[]) remoteMethods.clone(); + return remoteMethods.clone(); } /** @@ -204,8 +204,8 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { * chain, add each directly-implemented interface that * somehow extends Remote to a list. */ - Vector remotesImplemented = // list of remote interfaces found - new Vector(); + Vector<ClassDefinition> remotesImplemented = // list of remote interfaces found + new Vector<ClassDefinition>(); for (ClassDefinition classDef = implClassDef; classDef != null;) { @@ -307,13 +307,13 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { * Now we collect the methods from all of the remote interfaces * into a hashtable. */ - Hashtable methods = new Hashtable(); + Hashtable<String, Method> methods = new Hashtable<String, Method>(); boolean errors = false; - for (Enumeration enumeration = remotesImplemented.elements(); + for (Enumeration<ClassDefinition> enumeration + = remotesImplemented.elements(); enumeration.hasMoreElements();) { - ClassDefinition interfaceDef = - (ClassDefinition) enumeration.nextElement(); + ClassDefinition interfaceDef = enumeration.nextElement(); if (!collectRemoteMethods(interfaceDef, methods)) errors = true; } @@ -336,10 +336,10 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { */ String[] orderedKeys = new String[methods.size()]; int count = 0; - for (Enumeration enumeration = methods.elements(); + for (Enumeration<Method> enumeration = methods.elements(); enumeration.hasMoreElements();) { - Method m = (Method) enumeration.nextElement(); + Method m = enumeration.nextElement(); String key = m.getNameAndDescriptor(); int i; for (i = count; i > 0; --i) { @@ -353,7 +353,7 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { } remoteMethods = new Method[methods.size()]; for (int i = 0; i < remoteMethods.length; i++) { - remoteMethods[i] = (Method) methods.get(orderedKeys[i]); + remoteMethods[i] = methods.get(orderedKeys[i]); /***** <DEBUG> */ if (env.verbose()) { System.out.print("[found remote method <" + i + ">: " + @@ -388,7 +388,7 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { * or false if an error occurred. */ private boolean collectRemoteMethods(ClassDefinition interfaceDef, - Hashtable table) + Hashtable<String, Method> table) { if (!interfaceDef.isInterface()) { throw new Error( @@ -529,7 +529,7 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { * the new method (see bugid 4070653). */ String key = newMethod.getNameAndDescriptor(); - Method oldMethod = (Method) table.get(key); + Method oldMethod = table.get(key); if (oldMethod != null) { newMethod = newMethod.mergeWith(oldMethod); if (newMethod == null) { @@ -684,7 +684,7 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { * methods that can be legally thrown in each of them. */ public ClassDeclaration[] getExceptions() { - return (ClassDeclaration[]) exceptions.clone(); + return exceptions.clone(); } /** @@ -789,7 +789,8 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { getNameAndDescriptor()); } - Vector legalExceptions = new Vector(); + Vector<ClassDeclaration> legalExceptions + = new Vector<ClassDeclaration>(); try { collectCompatibleExceptions( other.exceptions, exceptions, legalExceptions); @@ -814,7 +815,7 @@ public class RemoteClass implements sun.rmi.rmic.RMIConstants { */ private void collectCompatibleExceptions(ClassDeclaration[] from, ClassDeclaration[] with, - Vector list) + Vector<ClassDeclaration> list) throws ClassNotFound { for (int i = 0; i < from.length; i++) { diff --git a/src/share/classes/sun/rmi/rmic/newrmic/jrmp/RemoteClass.java b/src/share/classes/sun/rmi/rmic/newrmic/jrmp/RemoteClass.java index f22a652df..064d2d0cc 100644 --- a/src/share/classes/sun/rmi/rmic/newrmic/jrmp/RemoteClass.java +++ b/src/share/classes/sun/rmi/rmic/newrmic/jrmp/RemoteClass.java @@ -121,7 +121,7 @@ final class RemoteClass { * in the array). **/ ClassDoc[] remoteInterfaces() { - return (ClassDoc[]) remoteInterfaces.clone(); + return remoteInterfaces.clone(); } /** @@ -136,7 +136,7 @@ final class RemoteClass { * stub/skeleton protocol. **/ Method[] remoteMethods() { - return (Method[]) remoteMethods.clone(); + return remoteMethods.clone(); } /** @@ -559,7 +559,7 @@ final class RemoteClass { * methods that can be legally thrown by all of them. **/ ClassDoc[] exceptionTypes() { - return (ClassDoc[]) exceptionTypes.clone(); + return exceptionTypes.clone(); } /** diff --git a/src/share/classes/sun/rmi/runtime/Log.java b/src/share/classes/sun/rmi/runtime/Log.java index 3eb8ce9cf..8017ee0a1 100644 --- a/src/share/classes/sun/rmi/runtime/Log.java +++ b/src/share/classes/sun/rmi/runtime/Log.java @@ -71,7 +71,7 @@ public abstract class Log { private static final LogFactory logFactory; static { boolean useOld = - Boolean.valueOf((String) java.security.AccessController. + Boolean.valueOf(java.security.AccessController. doPrivileged(new sun.security.action.GetPropertyAction( "sun.rmi.log.useOld"))).booleanValue(); @@ -179,17 +179,16 @@ public abstract class Log { private static class LoggerLog extends Log { /* alternate console handler for RMI loggers */ - private static final Handler alternateConsole = (Handler) + private static final Handler alternateConsole = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Handler>() { + public Handler run() { InternalStreamHandler alternate = new InternalStreamHandler(System.err); alternate.setLevel(Level.ALL); return alternate; } - } - ); + }); /** handler to which messages are copied */ private InternalStreamHandler copyHandler = null; @@ -206,8 +205,8 @@ public abstract class Log { if (level != null){ java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { if (!logger.isLoggable(level)) { logger.setLevel(level); } diff --git a/src/share/classes/sun/rmi/server/LoaderHandler.java b/src/share/classes/sun/rmi/server/LoaderHandler.java index d4a9183e4..dcdecb0cc 100644 --- a/src/share/classes/sun/rmi/server/LoaderHandler.java +++ b/src/share/classes/sun/rmi/server/LoaderHandler.java @@ -70,7 +70,7 @@ public final class LoaderHandler { /** RMI class loader log level */ static final int logLevel = LogStream.parseLevel( - (String) java.security.AccessController.doPrivileged( + java.security.AccessController.doPrivileged( new GetPropertyAction("sun.rmi.loader.logLevel"))); /* loader system log */ @@ -83,7 +83,7 @@ public final class LoaderHandler { */ private static String codebaseProperty = null; static { - String prop = (String) java.security.AccessController.doPrivileged( + String prop = java.security.AccessController.doPrivileged( new GetPropertyAction("java.rmi.server.codebase")); if (prop != null && prop.trim().length() > 0) { codebaseProperty = prop; @@ -94,8 +94,8 @@ public final class LoaderHandler { private static URL[] codebaseURLs = null; /** table of class loaders that use codebase property for annotation */ - private static final Map codebaseLoaders = - Collections.synchronizedMap(new IdentityHashMap(5)); + private static final Map<ClassLoader, Void> codebaseLoaders = + Collections.synchronizedMap(new IdentityHashMap<ClassLoader, Void>(5)); static { for (ClassLoader codebaseLoader = ClassLoader.getSystemClassLoader(); codebaseLoader != null; @@ -111,10 +111,12 @@ public final class LoaderHandler { * references, so this table does not prevent loaders from being * garbage collected. */ - private static final HashMap loaderTable = new HashMap(5); + private static final HashMap<LoaderKey, LoaderEntry> loaderTable + = new HashMap<LoaderKey, LoaderEntry>(5); /** reference queue for cleared class loader entries */ - private static final ReferenceQueue refQueue = new ReferenceQueue(); + private static final ReferenceQueue<Loader> refQueue + = new ReferenceQueue<Loader>(); /* * Disallow anyone from creating one of these. @@ -757,7 +759,7 @@ public final class LoaderHandler { throws MalformedURLException { synchronized (pathToURLsCache) { - Object[] v = (Object[]) pathToURLsCache.get(path); + Object[] v = pathToURLsCache.get(path); if (v != null) { return ((URL[])v[0]); } @@ -769,13 +771,14 @@ public final class LoaderHandler { } synchronized (pathToURLsCache) { pathToURLsCache.put(path, - new Object[] {urls, new SoftReference(path)}); + new Object[] {urls, new SoftReference<String>(path)}); } return urls; } /** map from weak(key=string) to [URL[], soft(key)] */ - private static final Map pathToURLsCache = new WeakHashMap(5); + private static final Map<String, Object[]> pathToURLsCache + = new WeakHashMap<String, Object[]>(5); /** * Convert an array of URL objects into a corresponding string @@ -853,9 +856,9 @@ public final class LoaderHandler { * in the table of RMI class loaders. */ LoaderKey key = new LoaderKey(urls, parent); - entry = (LoaderEntry) loaderTable.get(key); + entry = loaderTable.get(key); - if (entry == null || (loader = (Loader) entry.get()) == null) { + if (entry == null || (loader = entry.get()) == null) { /* * If entry was in table but it's weak reference was cleared, * remove it from the table and mark it as explicitly cleared, @@ -876,9 +879,9 @@ public final class LoaderHandler { * necessary to load classes from its codebase URL path. */ AccessControlContext acc = getLoaderAccessControlContext(urls); - loader = (Loader) java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + loader = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction<Loader>() { + public Loader run() { return new Loader(urls, parent); } }, acc); @@ -954,7 +957,7 @@ public final class LoaderHandler { * loader key for the loader so that the mapping can be removed from * the table efficiently when the weak reference is cleared. */ - private static class LoaderEntry extends WeakReference { + private static class LoaderEntry extends WeakReference<Loader> { public LoaderKey key; @@ -983,10 +986,10 @@ public final class LoaderHandler { * getAccessControlContext() in the sun.applet.AppletPanel class. */ // begin with permissions granted to all code in current policy - PermissionCollection perms = (PermissionCollection) + PermissionCollection perms = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<PermissionCollection>() { + public PermissionCollection run() { CodeSource codesource = new CodeSource(null, (java.security.cert.Certificate[]) null); Policy p = java.security.Policy.getPolicy(); diff --git a/src/share/classes/sun/rmi/server/MarshalInputStream.java b/src/share/classes/sun/rmi/server/MarshalInputStream.java index a75b8051a..cf4e345d7 100644 --- a/src/share/classes/sun/rmi/server/MarshalInputStream.java +++ b/src/share/classes/sun/rmi/server/MarshalInputStream.java @@ -59,18 +59,20 @@ public class MarshalInputStream extends ObjectInputStream { * as cached at class initialization time. */ private static final boolean useCodebaseOnlyProperty = - ((Boolean) java.security.AccessController.doPrivileged( + java.security.AccessController.doPrivileged( new sun.security.action.GetBooleanAction( - "java.rmi.server.useCodebaseOnly"))).booleanValue(); + "java.rmi.server.useCodebaseOnly")).booleanValue(); /** table to hold sun classes to which access is explicitly permitted */ - protected static Map permittedSunClasses = new HashMap(3); + protected static Map<String, Class<?>> permittedSunClasses + = new HashMap<String, Class<?>>(3); /** if true, don't try superclass first in resolveClass() */ private boolean skipDefaultResolveClass = false; /** callbacks to make when done() called: maps Object to Runnable */ - private final Map doneCallbacks = new HashMap(3); + private final Map<Object, Runnable> doneCallbacks + = new HashMap<Object, Runnable>(3); /** * if true, load classes (if not available locally) only from the @@ -130,7 +132,7 @@ public class MarshalInputStream extends ObjectInputStream { * with that key. */ public Runnable getDoneCallback(Object key) { - return (Runnable) doneCallbacks.get(key); // not thread-safe + return doneCallbacks.get(key); // not thread-safe } /** @@ -153,9 +155,9 @@ public class MarshalInputStream extends ObjectInputStream { * the superclass's close method. */ public void done() { - Iterator iter = doneCallbacks.values().iterator(); + Iterator<Runnable> iter = doneCallbacks.values().iterator(); while (iter.hasNext()) { // not thread-safe - Runnable callback = (Runnable) iter.next(); + Runnable callback = iter.next(); callback.run(); } doneCallbacks.clear(); @@ -276,8 +278,7 @@ public class MarshalInputStream extends ObjectInputStream { name = perm.getName(); } - Class resolvedClass = - (Class) permittedSunClasses.get(className); + Class<?> resolvedClass = permittedSunClasses.get(className); // if class not permitted, throw the SecurityException if ((name == null) || diff --git a/src/share/classes/sun/rmi/server/MarshalOutputStream.java b/src/share/classes/sun/rmi/server/MarshalOutputStream.java index 63aed2bee..067a5f2ec 100644 --- a/src/share/classes/sun/rmi/server/MarshalOutputStream.java +++ b/src/share/classes/sun/rmi/server/MarshalOutputStream.java @@ -64,8 +64,8 @@ public class MarshalOutputStream extends ObjectOutputStream super(out); this.useProtocolVersion(protocolVersion); java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { enableReplaceObject(true); return null; } diff --git a/src/share/classes/sun/rmi/server/Util.java b/src/share/classes/sun/rmi/server/Util.java index f103319ce..f75787441 100644 --- a/src/share/classes/sun/rmi/server/Util.java +++ b/src/share/classes/sun/rmi/server/Util.java @@ -67,7 +67,7 @@ public final class Util { /** "server" package log level */ static final int logLevel = LogStream.parseLevel( - (String) AccessController.doPrivileged( + AccessController.doPrivileged( new GetPropertyAction("sun.rmi.server.logLevel"))); /** server reference log */ @@ -76,13 +76,13 @@ public final class Util { /** cached value of property java.rmi.server.ignoreStubClasses */ private static final boolean ignoreStubClasses = - ((Boolean) AccessController.doPrivileged( - new GetBooleanAction("java.rmi.server.ignoreStubClasses"))). + AccessController.doPrivileged( + new GetBooleanAction("java.rmi.server.ignoreStubClasses")). booleanValue(); /** cache of impl classes that have no corresponding stub class */ - private static final Map withoutStubs = - Collections.synchronizedMap(new WeakHashMap(11)); + private static final Map<Class<?>, Void> withoutStubs = + Collections.synchronizedMap(new WeakHashMap<Class<?>, Void>(11)); /** parameter types for stub constructor */ private static final Class[] stubConsParamTypes = { RemoteRef.class }; @@ -207,9 +207,9 @@ public final class Util { * @throws NullPointerException if remoteClass is null */ private static Class[] getRemoteInterfaces(Class remoteClass) { - ArrayList list = new ArrayList(); + ArrayList<Class<?>> list = new ArrayList<Class<?>>(); getRemoteInterfaces(list, remoteClass); - return (Class []) list.toArray(new Class[list.size()]); + return list.toArray(new Class<?>[list.size()]); } /** @@ -220,7 +220,7 @@ public final class Util { * any illegal remote interfaces * @throws NullPointerException if the specified class or list is null */ - private static void getRemoteInterfaces(ArrayList list, Class cl) { + private static void getRemoteInterfaces(ArrayList<Class<?>> list, Class cl) { Class superclass = cl.getSuperclass(); if (superclass != null) { getRemoteInterfaces(list, superclass); @@ -254,7 +254,7 @@ public final class Util { * @throws IllegalArgumentException if m is an illegal remote method */ private static void checkMethod(Method m) { - Class[] ex = m.getExceptionTypes(); + Class<?>[] ex = m.getExceptionTypes(); for (int i = 0; i < ex.length; i++) { if (ex[i].isAssignableFrom(RemoteException.class)) return; @@ -283,7 +283,7 @@ public final class Util { * pickle methods */ try { - Class stubcl = + Class<?> stubcl = Class.forName(stubname, false, remoteClass.getClassLoader()); Constructor cons = stubcl.getConstructor(stubConsParamTypes); return (RemoteStub) cons.newInstance(new Object[] { ref }); diff --git a/src/share/classes/sun/rmi/server/WeakClassHashMap.java b/src/share/classes/sun/rmi/server/WeakClassHashMap.java index e822c2655..331930c36 100644 --- a/src/share/classes/sun/rmi/server/WeakClassHashMap.java +++ b/src/share/classes/sun/rmi/server/WeakClassHashMap.java @@ -69,7 +69,7 @@ public abstract class WeakClassHashMap<V> { synchronized (valueCell) { V value = null; if (valueCell.ref != null) { - value = (V) valueCell.ref.get(); + value = valueCell.ref.get(); } if (value == null) { value = computeValue(remoteClass); diff --git a/src/share/classes/sun/rmi/transport/DGCClient.java b/src/share/classes/sun/rmi/transport/DGCClient.java index 31784b357..585901bbc 100644 --- a/src/share/classes/sun/rmi/transport/DGCClient.java +++ b/src/share/classes/sun/rmi/transport/DGCClient.java @@ -85,21 +85,21 @@ final class DGCClient { /** lease duration to request (usually ignored by server) */ private static final long leaseValue = // default 10 minutes - ((Long) AccessController.doPrivileged( + AccessController.doPrivileged( new GetLongAction("java.rmi.dgc.leaseValue", - 600000))).longValue(); + 600000)).longValue(); /** maximum interval between retries of failed clean calls */ private static final long cleanInterval = // default 3 minutes - ((Long) AccessController.doPrivileged( + AccessController.doPrivileged( new GetLongAction("sun.rmi.dgc.cleanInterval", - 180000))).longValue(); + 180000)).longValue(); /** maximum interval between complete garbage collections of local heap */ private static final long gcInterval = // default 1 hour - ((Long) AccessController.doPrivileged( + AccessController.doPrivileged( new GetLongAction("sun.rmi.dgc.client.gcInterval", - 3600000))).longValue(); + 3600000)).longValue(); /** minimum retry count for dirty calls that fail */ private static final int dirtyFailureRetries = 5; @@ -243,7 +243,7 @@ final class DGCClient { } catch (RemoteException e) { throw new Error("internal error creating DGC stub"); } - renewCleanThread = (Thread) AccessController.doPrivileged( + renewCleanThread = AccessController.doPrivileged( new NewThreadAction(new RenewCleanThread(), "RenewClean-" + endpoint, true)); renewCleanThread.start(); @@ -473,8 +473,9 @@ final class DGCClient { if (newRenewTime < renewTime) { renewTime = newRenewTime; if (interruptible) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + AccessController.doPrivileged( + new PrivilegedAction<Void>() { + public Void run() { renewCleanThread.interrupt(); return null; } diff --git a/src/share/classes/sun/rmi/transport/Target.java b/src/share/classes/sun/rmi/transport/Target.java index 01df43800..6abf092d7 100644 --- a/src/share/classes/sun/rmi/transport/Target.java +++ b/src/share/classes/sun/rmi/transport/Target.java @@ -321,7 +321,7 @@ public final class Target { Remote obj = getImpl(); if (obj instanceof Unreferenced) { final Unreferenced unrefObj = (Unreferenced) obj; - final Thread t = (Thread) + final Thread t = java.security.AccessController.doPrivileged( new NewThreadAction(new Runnable() { public void run() { @@ -334,8 +334,8 @@ public final class Target { * for threads that may invoke user code (see bugid 4171278). */ java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { t.setContextClassLoader(ccl); return null; } diff --git a/src/share/classes/sun/rmi/transport/Transport.java b/src/share/classes/sun/rmi/transport/Transport.java index 572a55b2b..67e6058d9 100644 --- a/src/share/classes/sun/rmi/transport/Transport.java +++ b/src/share/classes/sun/rmi/transport/Transport.java @@ -53,7 +53,7 @@ public abstract class Transport { static final int logLevel = LogStream.parseLevel(getLogLevel()); private static String getLogLevel() { - return (String) java.security.AccessController.doPrivileged( + return java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("sun.rmi.transport.logLevel")); } @@ -171,8 +171,8 @@ public abstract class Transport { currentTransport.set(this); try { java.security.AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Object run() throws IOException { + new java.security.PrivilegedExceptionAction<Void>() { + public Void run() throws IOException { checkAcceptPermission(acc); disp.dispatch(impl, call); return null; diff --git a/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java b/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java index 3d91ab0d1..cb4a88e56 100644 --- a/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java +++ b/src/share/classes/sun/rmi/transport/proxy/CGIHandler.java @@ -89,8 +89,8 @@ public final class CGIHandler { static { java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { + new java.security.PrivilegedAction<Void>() { + public Void run() { ContentLength = Integer.getInteger("CONTENT_LENGTH", 0).intValue(); QueryString = System.getProperty("QUERY_STRING", ""); diff --git a/src/share/classes/sun/rmi/transport/proxy/HttpSendSocket.java b/src/share/classes/sun/rmi/transport/proxy/HttpSendSocket.java index 7498c9bfd..2c972d876 100644 --- a/src/share/classes/sun/rmi/transport/proxy/HttpSendSocket.java +++ b/src/share/classes/sun/rmi/transport/proxy/HttpSendSocket.java @@ -78,7 +78,7 @@ class HttpSendSocket extends Socket implements RMISocketInfo { * property at the moment that the socket was created. */ private String lineSeparator = - (String) java.security.AccessController.doPrivileged( + java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("line.separator")); /** diff --git a/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java b/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java index 16735959e..92d0dd77c 100644 --- a/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java +++ b/src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java @@ -50,7 +50,7 @@ public class RMIMasterSocketFactory extends RMISocketFactory { static int logLevel = LogStream.parseLevel(getLogLevel()); private static String getLogLevel() { - return (String) java.security.AccessController.doPrivileged( + return java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("sun.rmi.transport.proxy.logLevel")); } @@ -63,15 +63,15 @@ public class RMIMasterSocketFactory extends RMISocketFactory { private static long connectTimeout = getConnectTimeout(); private static long getConnectTimeout() { - return ((Long) java.security.AccessController.doPrivileged( + return java.security.AccessController.doPrivileged( new GetLongAction("sun.rmi.transport.proxy.connectTimeout", - 15000))).longValue(); // default: 15 seconds + 15000)).longValue(); // default: 15 seconds } /** whether to fallback to HTTP on general connect failures */ - private static final boolean eagerHttpFallback = ((Boolean) + private static final boolean eagerHttpFallback = java.security.AccessController.doPrivileged(new GetBooleanAction( - "sun.rmi.transport.proxy.eagerHttpFallback"))).booleanValue(); + "sun.rmi.transport.proxy.eagerHttpFallback")).booleanValue(); /** table of hosts successfully connected to and the factory used */ private Hashtable successTable = new Hashtable(); @@ -100,14 +100,14 @@ public class RMIMasterSocketFactory extends RMISocketFactory { try { String proxyHost; - proxyHost = (String) java.security.AccessController.doPrivileged( + proxyHost = java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("http.proxyHost")); if (proxyHost == null) - proxyHost=(String)java.security.AccessController.doPrivileged( + proxyHost = java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("proxyHost")); - Boolean tmp = (Boolean)java.security.AccessController.doPrivileged( + Boolean tmp = java.security.AccessController.doPrivileged( new sun.security.action.GetBooleanAction("java.rmi.server.disableHttp")); if (!tmp.booleanValue() && @@ -178,10 +178,8 @@ public class RMIMasterSocketFactory extends RMISocketFactory { try { synchronized (connector) { - Thread t = (Thread) - java.security.AccessController.doPrivileged( - new NewThreadAction(connector, "AsyncConnector", - true)); + Thread t = java.security.AccessController.doPrivileged( + new NewThreadAction(connector, "AsyncConnector", true)); t.start(); try { diff --git a/src/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java b/src/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java index f756cd34f..ac26ac6d8 100644 --- a/src/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java +++ b/src/share/classes/sun/rmi/transport/tcp/ConnectionMultiplexer.java @@ -49,7 +49,7 @@ final class ConnectionMultiplexer { static int logLevel = LogStream.parseLevel(getLogLevel()); private static String getLogLevel() { - return (String) java.security.AccessController.doPrivileged( + return java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction("sun.rmi.transport.tcp.multiplex.logLevel")); } diff --git a/src/share/classes/sun/security/jgss/GSSManagerImpl.java b/src/share/classes/sun/security/jgss/GSSManagerImpl.java index 7bf0f9be2..7aa401b03 100644 --- a/src/share/classes/sun/security/jgss/GSSManagerImpl.java +++ b/src/share/classes/sun/security/jgss/GSSManagerImpl.java @@ -83,7 +83,7 @@ public class GSSManagerImpl extends GSSManager { public Oid[] getNamesForMech(Oid mech) throws GSSException { MechanismFactory factory = list.getMechFactory(mech); - return (Oid[])factory.getNameTypes().clone(); + return factory.getNameTypes().clone(); } public Oid[] getMechsForName(Oid nameType){ diff --git a/src/share/classes/sun/security/jgss/krb5/InitSecContextToken.java b/src/share/classes/sun/security/jgss/krb5/InitSecContextToken.java index 0fcbe12ff..838f6f8df 100644 --- a/src/share/classes/sun/security/jgss/krb5/InitSecContextToken.java +++ b/src/share/classes/sun/security/jgss/krb5/InitSecContextToken.java @@ -103,8 +103,7 @@ class InitSecContextToken extends InitialToken { apReq = new KrbApReq(apReqBytes, keys, addr); //debug("\nReceived AP-REQ and authenticated it.\n"); - EncryptionKey sessionKey - = (EncryptionKey) apReq.getCreds().getSessionKey(); + EncryptionKey sessionKey = apReq.getCreds().getSessionKey(); /* System.out.println("\n\nSession key from service ticket is: " + diff --git a/src/share/classes/sun/security/ssl/CipherSuite.java b/src/share/classes/sun/security/ssl/CipherSuite.java index 794f7179f..81a3696f7 100644 --- a/src/share/classes/sun/security/ssl/CipherSuite.java +++ b/src/share/classes/sun/security/ssl/CipherSuite.java @@ -191,7 +191,7 @@ final class CipherSuite implements Comparable { if (s == null) { throw new IllegalArgumentException("Name must not be null"); } - CipherSuite c = (CipherSuite)nameMap.get(s); + CipherSuite c = nameMap.get(s); if ((c == null) || (c.allowed == false)) { throw new IllegalArgumentException("Unsupported ciphersuite " + s); } @@ -395,7 +395,7 @@ final class CipherSuite implements Comparable { } private static synchronized boolean isAvailable(BulkCipher cipher) { - Boolean b = (Boolean)availableCache.get(cipher); + Boolean b = availableCache.get(cipher); if (b == null) { try { SecretKey key = new SecretKeySpec diff --git a/src/share/classes/sun/security/ssl/DHCrypt.java b/src/share/classes/sun/security/ssl/DHCrypt.java index baf784cde..5c9dc14aa 100644 --- a/src/share/classes/sun/security/ssl/DHCrypt.java +++ b/src/share/classes/sun/security/ssl/DHCrypt.java @@ -132,8 +132,7 @@ final class DHCrypt { } try { KeyFactory factory = JsseJce.getKeyFactory("DH"); - return (DHPublicKeySpec)factory.getKeySpec - (key, DHPublicKeySpec.class); + return factory.getKeySpec(key, DHPublicKeySpec.class); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/share/classes/sun/security/ssl/JsseJce.java b/src/share/classes/sun/security/ssl/JsseJce.java index 5fb697287..d9a40fb2b 100644 --- a/src/share/classes/sun/security/ssl/JsseJce.java +++ b/src/share/classes/sun/security/ssl/JsseJce.java @@ -343,8 +343,7 @@ final class JsseJce { } try { KeyFactory factory = JsseJce.getKeyFactory("RSA"); - return (RSAPublicKeySpec)factory.getKeySpec - (key, RSAPublicKeySpec.class); + return factory.getKeySpec(key, RSAPublicKeySpec.class); } catch (Exception e) { throw (RuntimeException)new RuntimeException().initCause(e); } diff --git a/src/share/classes/sun/security/ssl/ProtocolList.java b/src/share/classes/sun/security/ssl/ProtocolList.java index 9898d244a..197cfa4ad 100644 --- a/src/share/classes/sun/security/ssl/ProtocolList.java +++ b/src/share/classes/sun/security/ssl/ProtocolList.java @@ -98,7 +98,7 @@ final class ProtocolList { protocolNames[i++] = version.name; } } - return (String[])protocolNames.clone(); + return protocolNames.clone(); } public String toString() { diff --git a/src/share/classes/sun/security/ssl/SSLSessionImpl.java b/src/share/classes/sun/security/ssl/SSLSessionImpl.java index 38d666ac3..a37954ea2 100644 --- a/src/share/classes/sun/security/ssl/SSLSessionImpl.java +++ b/src/share/classes/sun/security/ssl/SSLSessionImpl.java @@ -458,7 +458,7 @@ final class SSLSessionImpl implements SSLSession { + " for Kerberos cipher suites"); } if (peerCerts != null) { - return (X509Certificate [])peerCerts.clone(); + return peerCerts.clone(); } else { throw new SSLPeerUnverifiedException("peer not authenticated"); } @@ -489,7 +489,7 @@ final class SSLSessionImpl implements SSLSession { if (peerCerts == null) { throw new SSLPeerUnverifiedException("peer not authenticated"); } - return ((X500Principal)peerCerts[0].getSubjectX500Principal()); + return peerCerts[0].getSubjectX500Principal(); } /** @@ -508,7 +508,7 @@ final class SSLSessionImpl implements SSLSession { (KerberosPrincipal)localPrincipal); } return (localCerts == null ? null : - (X500Principal)localCerts[0].getSubjectX500Principal()); + localCerts[0].getSubjectX500Principal()); } /** diff --git a/src/share/classes/sun/security/ssl/SessionId.java b/src/share/classes/sun/security/ssl/SessionId.java index 557fbff30..c9b900f74 100644 --- a/src/share/classes/sun/security/ssl/SessionId.java +++ b/src/share/classes/sun/security/ssl/SessionId.java @@ -64,7 +64,7 @@ class SessionId /** Returns the bytes in the ID. May be an empty array. */ byte [] getId () { - return (byte []) sessionId.clone (); + return sessionId.clone (); } /** Returns the ID as a string */ diff --git a/src/share/classes/sun/security/ssl/SunX509KeyManagerImpl.java b/src/share/classes/sun/security/ssl/SunX509KeyManagerImpl.java index a111f79b4..2cd825def 100644 --- a/src/share/classes/sun/security/ssl/SunX509KeyManagerImpl.java +++ b/src/share/classes/sun/security/ssl/SunX509KeyManagerImpl.java @@ -172,7 +172,7 @@ final class SunX509KeyManagerImpl extends X509ExtendedKeyManager { if (cred == null) { return null; } else { - return (X509Certificate[])cred.certificates.clone(); + return cred.certificates.clone(); } } @@ -255,7 +255,7 @@ final class SunX509KeyManagerImpl extends X509ExtendedKeyManager { String[] aliases; if (issuers == null || issuers.length == 0) { - aliases = (String[])serverAliasCache.get(keyType); + aliases = serverAliasCache.get(keyType); if (aliases == null) { aliases = getServerAliases(keyType, issuers); // Cache the result (positive and negative lookups) @@ -388,7 +388,7 @@ final class SunX509KeyManagerImpl extends X509ExtendedKeyManager { } } - String[] aliasStrings = (String[])aliases.toArray(STRING0); + String[] aliasStrings = aliases.toArray(STRING0); return ((aliasStrings.length == 0) ? null : aliasStrings); } diff --git a/src/share/classes/sun/security/x509/CertificatePolicySet.java b/src/share/classes/sun/security/x509/CertificatePolicySet.java index 32e5121c7..514a3576c 100644 --- a/src/share/classes/sun/security/x509/CertificatePolicySet.java +++ b/src/share/classes/sun/security/x509/CertificatePolicySet.java @@ -87,7 +87,7 @@ public class CertificatePolicySet { DerOutputStream tmp = new DerOutputStream(); for (int i = 0; i < ids.size(); i++) { - ((CertificatePolicyId)ids.elementAt(i)).encode(tmp); + ids.elementAt(i).encode(tmp); } out.write(DerValue.tag_Sequence,tmp); } diff --git a/src/share/classes/sun/security/x509/X509Cert.java b/src/share/classes/sun/security/x509/X509Cert.java index 6777d4b4a..af6851112 100644 --- a/src/share/classes/sun/security/x509/X509Cert.java +++ b/src/share/classes/sun/security/x509/X509Cert.java @@ -516,7 +516,7 @@ public class X509Cert implements Certificate, Serializable { * Null is returned in the case of a partially constructed cert. */ public byte [] getSignedCert () - { return (byte[])signedCert.clone(); } + { return signedCert.clone(); } /** diff --git a/src/share/classes/sun/tools/jar/JarVerifierStream.java b/src/share/classes/sun/tools/jar/JarVerifierStream.java index 5485bfade..c39b35eaa 100644 --- a/src/share/classes/sun/tools/jar/JarVerifierStream.java +++ b/src/share/classes/sun/tools/jar/JarVerifierStream.java @@ -32,7 +32,6 @@ import java.util.jar.*; import java.security.cert.Certificate; import java.security.AccessController; import java.security.cert.X509Certificate; -import java.security.Identity; import java.security.PublicKey; import java.security.Principal; import sun.security.provider.SystemIdentity; @@ -49,7 +48,8 @@ import sun.security.provider.SystemIdentity; public class JarVerifierStream extends ZipInputStream { private JarEntry current; - private Hashtable verified = new Hashtable(); + private Hashtable<String, Vector<SystemIdentity>> verified + = new Hashtable<String, Vector<SystemIdentity>>(); private JarInputStream jis; private sun.tools.jar.Manifest man = null; @@ -120,7 +120,7 @@ public class JarVerifierStream extends ZipInputStream { if (current != null) { Certificate[] certs = current.getCertificates(); if (certs != null) { - Vector ids = getIds(certs); + Vector<SystemIdentity> ids = getIds(certs); if (ids != null) { verified.put(current.getName(), ids); } @@ -189,7 +189,7 @@ public class JarVerifierStream extends ZipInputStream { static class CertCache { Certificate [] certs; - Vector ids; + Vector<SystemIdentity> ids; boolean equals(Certificate[] certs) { if (this.certs == null) { @@ -229,21 +229,21 @@ public class JarVerifierStream extends ZipInputStream { } } - private ArrayList certCache = null; + private ArrayList<CertCache> certCache = null; /** * Returns the Identity vector for the given array of Certificates */ - protected Vector getIds(Certificate[] certs) { + protected Vector<SystemIdentity> getIds(Certificate[] certs) { if (certs == null) return null; if (certCache == null) - certCache = new ArrayList(); + certCache = new ArrayList<CertCache>(); CertCache cc; for (int i = 0; i < certCache.size(); i++) { - cc = (CertCache) certCache.get(i); + cc = certCache.get(i); if (cc.equals(certs)) { return cc.ids; } @@ -265,8 +265,8 @@ public class JarVerifierStream extends ZipInputStream { new sun.security.x509.X509Cert(encoded); try { AccessController.doPrivileged( - new java.security.PrivilegedExceptionAction() { - public Object run() + new java.security.PrivilegedExceptionAction<Void>() { + public Void run() throws java.security.KeyManagementException { id.addCertificate(oldC); @@ -278,7 +278,7 @@ public class JarVerifierStream extends ZipInputStream { pae.getException(); } if (cc.ids == null) - cc.ids = new Vector(); + cc.ids = new Vector<SystemIdentity>(); cc.ids.addElement(id); } catch (java.security.KeyManagementException kme) { // ignore if we can't create Identity diff --git a/src/share/classes/sun/tools/native2ascii/N2AFilter.java b/src/share/classes/sun/tools/native2ascii/N2AFilter.java index 0a5706e06..82c807d2e 100644 --- a/src/share/classes/sun/tools/native2ascii/N2AFilter.java +++ b/src/share/classes/sun/tools/native2ascii/N2AFilter.java @@ -42,7 +42,7 @@ class N2AFilter extends FilterWriter { public void write(char b) throws IOException { char[] buf = new char[1]; - buf[0] = (char)b; + buf[0] = b; write(buf, 0, 1); } |