# HG changeset patch # User henryjen # Date 1403546050 25200 # Mon Jun 23 10:54:10 2014 -0700 # Node ID fbc95e4960062f328afa9737d5e5dd308e28479d # Parent 08319e8e76ce19f149d971ba9f700d3540cfd4e1 8042872: Fix raw and unchecked warnings in sun.applet Reviewed-by: diff --git a/src/share/classes/sun/applet/AppletClassLoader.java b/src/share/classes/sun/applet/AppletClassLoader.java --- a/src/share/classes/sun/applet/AppletClassLoader.java +++ b/src/share/classes/sun/applet/AppletClassLoader.java @@ -137,7 +137,7 @@ * Override loadClass so that class loading errors can be caught in * order to print better error messages. */ - public synchronized Class loadClass(String name, boolean resolve) + public synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { // First check if we have permission to access the package. This @@ -166,7 +166,7 @@ * Finds the applet class with the specified name. First searches * loaded JAR files then the applet code base for the class. */ - protected Class findClass(String name) throws ClassNotFoundException { + protected Class findClass(String name) throws ClassNotFoundException { int index = name.indexOf(';'); String cookie = ""; @@ -192,9 +192,9 @@ String encodedName = ParseUtil.encodePath(name.replace('.', '/'), false); final String path = (new StringBuffer(encodedName)).append(".class").append(cookie).toString(); try { - byte[] b = (byte[]) AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Object run() throws IOException { + byte[] b = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public byte[] run() throws IOException { try { URL finalURL = new URL(base, path); @@ -556,9 +556,10 @@ * name. First checks loaded JAR files then the applet code base for all * available resources. */ - public Enumeration findResources(String name) throws IOException { + @Override + public Enumeration findResources(String name) throws IOException { - final Enumeration e = super.findResources(name); + final Enumeration e = super.findResources(name); // 6215746: Disable META-INF/* lookup from codebase in // applet/plugin classloader. [stanley.ho] @@ -576,9 +577,9 @@ } final URL url = u; - return new Enumeration() { + return new Enumeration() { private boolean done; - public Object nextElement() { + public URL nextElement() { if (!done) { if (e.hasMoreElements()) { return e.nextElement(); @@ -601,7 +602,7 @@ * attribute. The argument can either be the relative path * of the class file itself or just the name of the class. */ - Class loadCode(String name) throws ClassNotFoundException { + Class loadCode(String name) throws ClassNotFoundException { // first convert any '/' or native file separator to . name = name.replace('/', '.'); name = name.replace(File.separatorChar, '.'); @@ -646,7 +647,7 @@ public ThreadGroup getThreadGroup() { synchronized (threadGroupSynchronizer) { if (threadGroup == null || threadGroup.isDestroyed()) { - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction() { public Object run() { threadGroup = new AppletThreadGroup(base + "-threadGroup"); // threadGroup.setDaemon(true); @@ -770,8 +771,8 @@ // Hash map to store applet compatibility info - private HashMap jdk11AppletInfo = new HashMap(); - private HashMap jdk12AppletInfo = new HashMap(); + private HashMap jdk11AppletInfo = new HashMap<>(); + private HashMap jdk12AppletInfo = new HashMap<>(); /** * Set applet target level as JDK 1.1. @@ -780,7 +781,7 @@ * @param bool true if JDK is targeted for JDK 1.1; * false otherwise. */ - void setJDK11Target(Class clazz, boolean bool) + void setJDK11Target(Class clazz, boolean bool) { jdk11AppletInfo.put(clazz.toString(), Boolean.valueOf(bool)); } @@ -792,7 +793,7 @@ * @param bool true if JDK is targeted for JDK 1.2; * false otherwise. */ - void setJDK12Target(Class clazz, boolean bool) + void setJDK12Target(Class clazz, boolean bool) { jdk12AppletInfo.put(clazz.toString(), Boolean.valueOf(bool)); } @@ -805,9 +806,9 @@ * FALSE if applet is not; * null if applet is unknown. */ - Boolean isJDK11Target(Class clazz) + Boolean isJDK11Target(Class clazz) { - return (Boolean) jdk11AppletInfo.get(clazz.toString()); + return jdk11AppletInfo.get(clazz.toString()); } /** @@ -818,9 +819,9 @@ * FALSE if applet is not; * null if applet is unknown. */ - Boolean isJDK12Target(Class clazz) + Boolean isJDK12Target(Class clazz) { - return (Boolean) jdk12AppletInfo.get(clazz.toString()); + return jdk12AppletInfo.get(clazz.toString()); } private static AppletMessageHandler mh = diff --git a/src/share/classes/sun/applet/AppletImageRef.java b/src/share/classes/sun/applet/AppletImageRef.java --- a/src/share/classes/sun/applet/AppletImageRef.java +++ b/src/share/classes/sun/applet/AppletImageRef.java @@ -65,7 +65,7 @@ * invoke reconstitute(). */ public synchronized void flush() { - SoftReference s = soft; + SoftReference s = soft; if (s != null) s.clear(); soft = null; } @@ -74,9 +74,9 @@ * Sets the thing to the specified object. * @param thing the specified object */ - public synchronized void setThing(Object thing) { + public synchronized void setThing(Image thing) { flush(); - soft = new SoftReference(thing); + soft = new SoftReference<>(thing); } /** diff --git a/src/share/classes/sun/applet/AppletObjectInputStream.java b/src/share/classes/sun/applet/AppletObjectInputStream.java --- a/src/share/classes/sun/applet/AppletObjectInputStream.java +++ b/src/share/classes/sun/applet/AppletObjectInputStream.java @@ -59,7 +59,7 @@ * Make a primitive array class */ - private Class primitiveType(char type) { + private Class primitiveType(char type) { switch (type) { case 'B': return byte.class; case 'C': return char.class; @@ -76,13 +76,13 @@ /** * Use the given ClassLoader rather than using the system class */ - protected Class resolveClass(ObjectStreamClass classDesc) + protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException { String cname = classDesc.getName(); if (cname.startsWith("[")) { // An array - Class component; // component class + Class component; // component class int dcount; // dimension for (dcount=1; cname.charAt(dcount)=='['; dcount++) ; if (cname.charAt(dcount) == 'L') { diff --git a/src/share/classes/sun/applet/AppletPanel.java b/src/share/classes/sun/applet/AppletPanel.java --- a/src/share/classes/sun/applet/AppletPanel.java +++ b/src/share/classes/sun/applet/AppletPanel.java @@ -179,7 +179,7 @@ handler = new Thread(appletGroup, this, "thread " + nm); // set the context class loader for this thread - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction() { @Override public Object run() { handler.setContextClassLoader(loader); @@ -253,7 +253,7 @@ /** * AppletEvent Queue */ - private Queue queue = null; + private Queue queue = null; synchronized public void addAppletListener(AppletListener l) { @@ -282,7 +282,7 @@ synchronized(this) { if (queue == null) { //System.out.println("SEND0= " + id); - queue = new Queue(); + queue = new Queue<>(); } Integer eventId = Integer.valueOf(id); queue.enqueue(eventId); @@ -309,7 +309,7 @@ while (queue == null || queue.isEmpty()) { wait(); } - Integer eventId = (Integer)queue.dequeue(); + Integer eventId = queue.dequeue(); return new AppletEvent(this, eventId.intValue(), null); } @@ -631,14 +631,15 @@ * calls KeyboardFocusManager directly. */ private Component getMostRecentFocusOwnerForWindow(Window w) { - Method meth = (Method)AccessController.doPrivileged(new PrivilegedAction() { + Method meth = AccessController.doPrivileged( + new PrivilegedAction() { @Override - public Object run() { + public Method run() { Method meth = null; try { meth = KeyboardFocusManager.class.getDeclaredMethod( "getMostRecentFocusOwner", - new Class[]{Window.class}); + new Class[]{Window.class}); meth.setAccessible(true); } catch (Exception e) { // Must never happen @@ -988,7 +989,7 @@ /** * The class loaders */ - private static HashMap classloaders = new HashMap(); + private static HashMap classloaders = new HashMap<>(); /** * Flush a class loader. @@ -1001,7 +1002,7 @@ * Flush all class loaders. */ public static synchronized void flushClassLoaders() { - classloaders = new HashMap(); + classloaders = new HashMap<>(); } /** @@ -1018,14 +1019,14 @@ * Get a class loader. Create in a restricted context */ synchronized AppletClassLoader getClassLoader(final URL codebase, final String key) { - AppletClassLoader c = (AppletClassLoader)classloaders.get(key); + AppletClassLoader c = classloaders.get(key); if (c == null) { AccessControlContext acc = getAccessControlContext(codebase); - c = (AppletClassLoader) - AccessController.doPrivileged(new PrivilegedAction() { + c = AccessController.doPrivileged( + new PrivilegedAction() { @Override - public Object run() { + public AppletClassLoader run() { AppletClassLoader ac = createClassLoader(codebase); /* Should the creation of the classloader be * within the class synchronized block? Since @@ -1043,8 +1044,7 @@ * (which timeout when called from the browser). */ synchronized (getClass()) { - AppletClassLoader res = - (AppletClassLoader)classloaders.get(key); + AppletClassLoader res = classloaders.get(key); if (res == null) { classloaders.put(key, ac); return ac; @@ -1066,10 +1066,10 @@ */ private AccessControlContext getAccessControlContext(final URL codebase) { - PermissionCollection perms = (PermissionCollection) - AccessController.doPrivileged(new PrivilegedAction() { + PermissionCollection perms = AccessController.doPrivileged( + new PrivilegedAction() { @Override - public Object run() { + public PermissionCollection run() { Policy p = java.security.Policy.getPolicy(); if (p != null) { return p.getPermissions(new CodeSource(null, @@ -1172,13 +1172,15 @@ // critical section of the window list in AppContext. synchronized (Window.class) { - WeakReference weakRef = null; + WeakReference weakRef = null; // Remove frame from the Window list in wrong AppContext { // Lookup current frame's AppContext - Vector> windowList = (Vector>)oldAppContext.get(Window.class); + @SuppressWarnings("unchecked") + Vector> windowList = + (Vector>)oldAppContext.get(Window.class); if (windowList != null) { - for (WeakReference ref : windowList) { + for (WeakReference ref : windowList) { if (ref.get() == frame) { weakRef = ref; break; @@ -1195,7 +1197,9 @@ // Insert frame into the Window list in the applet's AppContext map { - Vector> windowList = (Vector)newAppContext.get(Window.class); + @SuppressWarnings("unchecked") + Vector> windowList = + (Vector>)newAppContext.get(Window.class); if (windowList == null) { windowList = new Vector>(); newAppContext.put(Window.class, windowList); @@ -1224,7 +1228,7 @@ // synchronized on applet class object, so calling from // different instances of the same applet will be // serialized. - Class appletClass = applet.getClass(); + Class appletClass = applet.getClass(); synchronized(appletClass) { // Determine if the JDK level of an applet has been diff --git a/src/share/classes/sun/applet/AppletProps.java b/src/share/classes/sun/applet/AppletProps.java --- a/src/share/classes/sun/applet/AppletProps.java +++ b/src/share/classes/sun/applet/AppletProps.java @@ -105,9 +105,9 @@ String proxyPortValue = proxyPort.getText().trim(); // Get properties - final Properties props = (Properties) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + final Properties props = AccessController.doPrivileged( + new PrivilegedAction() { + public Properties run() { return System.getProperties(); } }); @@ -148,7 +148,7 @@ // Save properties try { reset(); - AccessController.doPrivileged(new PrivilegedExceptionAction() { + AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException { File dotAV = Main.theUserPropertiesFile; FileOutputStream out = new FileOutputStream(dotAV); diff --git a/src/share/classes/sun/applet/AppletSecurity.java b/src/share/classes/sun/applet/AppletSecurity.java --- a/src/share/classes/sun/applet/AppletSecurity.java +++ b/src/share/classes/sun/applet/AppletSecurity.java @@ -80,7 +80,7 @@ } // Cache to store known restricted packages - private HashSet restrictedPackages = new HashSet(); + private HashSet restrictedPackages = new HashSet<>(); /** * Reset from Properties @@ -90,11 +90,11 @@ // Clear cache restrictedPackages.clear(); - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction() { public Object run() { // Enumerate system properties - Enumeration e = System.getProperties().propertyNames(); + Enumeration e = System.getProperties().propertyNames(); while (e.hasMoreElements()) { @@ -130,7 +130,7 @@ return (AppletClassLoader)loader; // if that fails, get all the classes on the stack and check them. - Class[] context = getClassContext(); + Class[] context = getClassContext(); for (int i = 0; i < context.length; i++) { loader = context[i].getClassLoader(); if (loader instanceof AppletClassLoader) @@ -148,37 +148,38 @@ final ClassLoader currentLoader = context[i].getClassLoader(); if (currentLoader instanceof URLClassLoader) { - loader = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + loader = AccessController.doPrivileged( + new PrivilegedAction() { + public ClassLoader run() { - AccessControlContext acc = null; - ProtectionDomain[] pds = null; + AccessControlContext acc = null; + ProtectionDomain[] pds = null; - try { - acc = (AccessControlContext) facc.get(currentLoader); - if (acc == null) { - return null; + try { + acc = (AccessControlContext) facc.get(currentLoader); + if (acc == null) { + return null; + } + + pds = (ProtectionDomain[]) fcontext.get(acc); + if (pds == null) { + return null; + } + } catch (Exception e) { + throw new UnsupportedOperationException(e); } - pds = (ProtectionDomain[]) fcontext.get(acc); - if (pds == null) { - return null; + for (int i=0; i iter = restrictedPackages.iterator(); iter.hasNext();) { - String pkg = (String) iter.next(); + String pkg = iter.next(); // Prevent matching "sun" and "sunir" even if they // starts with similar beginning characters diff --git a/src/share/classes/sun/applet/AppletViewer.java b/src/share/classes/sun/applet/AppletViewer.java --- a/src/share/classes/sun/applet/AppletViewer.java +++ b/src/share/classes/sun/applet/AppletViewer.java @@ -94,7 +94,7 @@ @Override public AppletViewer createAppletViewer(int x, int y, - URL doc, Hashtable atts) { + URL doc, Hashtable atts) { return new AppletViewer(x, y, doc, atts, System.out, this); } @@ -156,7 +156,7 @@ /** * Create the applet viewer. */ - public AppletViewer(int x, int y, URL doc, Hashtable atts, + public AppletViewer(int x, int y, URL doc, Hashtable atts, PrintStream statusMsgStream, AppletViewerFactory factory) { this.factory = factory; this.statusMsgStream = statusMsgStream; @@ -350,7 +350,7 @@ * s. Whitespace not stripped. */ private String [] splitSeparator(String sep, String s) { - Vector v = new Vector(); + Vector v = new Vector<>(); int tokenStart = 0; int tokenEnd = 0; @@ -370,7 +370,7 @@ * Methods for java.applet.AppletContext */ - private static Map audioClips = new HashMap(); + private static Map audioClips = new HashMap<>(); /** * Get an audio clip. @@ -379,7 +379,7 @@ public AudioClip getAudioClip(URL url) { checkConnect(url); synchronized (audioClips) { - AudioClip clip = (AudioClip)audioClips.get(url); + AudioClip clip = audioClips.get(url); if (clip == null) { audioClips.put(url, clip = new AppletAudioClip(url)); } @@ -387,7 +387,7 @@ } } - private static Map imageRefs = new HashMap(); + private static Map imageRefs = new HashMap<>(); /** * Get an image. @@ -403,7 +403,7 @@ static Image getCachedImage(URL url) { // System.getSecurityManager().checkConnection(url.getHost(), url.getPort()); synchronized (imageRefs) { - AppletImageRef ref = (AppletImageRef)imageRefs.get(url); + AppletImageRef ref = imageRefs.get(url); if (ref == null) { ref = new AppletImageRef(url); imageRefs.put(url, ref); @@ -419,7 +419,7 @@ imageRefs.clear(); } - static Vector appletPanels = new Vector(); + static Vector appletPanels = new Vector<>(); /** * Get an applet by name. @@ -430,8 +430,8 @@ name = name.toLowerCase(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); - for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { - AppletPanel p = (AppletPanel)e.nextElement(); + for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { + AppletPanel p = e.nextElement(); String param = p.getParameter("name"); if (param != null) { param = param.toLowerCase(); @@ -455,14 +455,14 @@ * applets on this page. */ @Override - public Enumeration getApplets() { + public Enumeration getApplets() { AppletSecurity security = (AppletSecurity)System.getSecurityManager(); - Vector v = new Vector(); + Vector v = new Vector<>(); SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect"); - for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { - AppletPanel p = (AppletPanel)e.nextElement(); + for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { + AppletPanel p = e.nextElement(); if (p.getDocumentBase().equals(panel.getDocumentBase())) { SocketPermission sp = @@ -509,7 +509,7 @@ } @Override - public Iterator getStreamKeys(){ + public Iterator getStreamKeys(){ // We do nothing. return null; } @@ -517,7 +517,7 @@ /** * System parameters. */ - static Hashtable systemParam = new Hashtable(); + static Hashtable systemParam = new Hashtable<>(); static { systemParam.put("codebase", "codebase"); @@ -533,32 +533,32 @@ /** * Print the HTML tag. */ - public static void printTag(PrintStream out, Hashtable atts) { + public static void printTag(PrintStream out, Hashtable atts) { out.print(" e = atts.keys() ; e.hasMoreElements() ;) { + String param = e.nextElement(); int i = 0; for (; i < len ; i++) { if (params[i].compareTo(param) >= 0) { @@ -649,7 +649,7 @@ * Save the applet to a well known file (for now) as a serialized object */ void appletSave() { - AccessController.doPrivileged(new PrivilegedAction() { + AccessController.doPrivileged(new PrivilegedAction() { @Override public Object run() { @@ -702,8 +702,10 @@ void appletClone() { Point p = location(); updateAtts(); + @SuppressWarnings("unchecked") + Hashtable tmp = (Hashtable) panel.atts.clone(); factory.createAppletViewer(p.x + XDELTA, p.y + YDELTA, - panel.documentURL, (Hashtable)panel.atts.clone()); + panel.documentURL, tmp); } /** @@ -884,8 +886,8 @@ @Override public void run() { - for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { - AppletPanel p = (AppletPanel)e.nextElement(); + for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { + AppletPanel p = e.nextElement(); appletShutdown(p); } appletSystemExit(); @@ -1016,8 +1018,8 @@ /** * Scan tag */ - public static Hashtable scanTag(Reader in) throws IOException { - Hashtable atts = new Hashtable(); + public static Hashtable scanTag(Reader in) throws IOException { + Hashtable atts = new Hashtable<>(); skipSpace(in); while (c >= 0 && c != '>') { String att = scanIdentifier(in); @@ -1122,7 +1124,7 @@ url = conn.getURL(); int ydisp = 1; - Hashtable atts = null; + Hashtable atts = null; while(true) { c = in.read(); @@ -1172,12 +1174,12 @@ else { String nm = scanIdentifier(in); if (nm.equalsIgnoreCase("param")) { - Hashtable t = scanTag(in); - String att = (String)t.get("name"); + Hashtable t = scanTag(in); + String att = t.get("name"); if (att == null) { statusMsgStream.println(requiresNameWarning); } else { - String val = (String)t.get("value"); + String val = t.get("value"); if (val == null) { statusMsgStream.println(requiresNameWarning); } else if (atts != null) { @@ -1235,13 +1237,13 @@ } else if (nm.equalsIgnoreCase("app")) { statusMsgStream.println(appNotLongerSupportedWarning); - Hashtable atts2 = scanTag(in); - nm = (String)atts2.get("class"); + Hashtable atts2 = scanTag(in); + nm = atts2.get("class"); if (nm != null) { atts2.remove("class"); atts2.put("code", nm + ".class"); } - nm = (String)atts2.get("src"); + nm = atts2.get("src"); if (nm != null) { atts2.remove("src"); atts2.put("codebase", nm); diff --git a/src/share/classes/sun/applet/AppletViewerFactory.java b/src/share/classes/sun/applet/AppletViewerFactory.java --- a/src/share/classes/sun/applet/AppletViewerFactory.java +++ b/src/share/classes/sun/applet/AppletViewerFactory.java @@ -35,7 +35,8 @@ public interface AppletViewerFactory { - public AppletViewer createAppletViewer(int x, int y, URL doc, Hashtable atts); + public AppletViewer createAppletViewer(int x, int y, URL doc, + Hashtable atts); public MenuBar getBaseMenuBar(); public boolean isStandalone(); } diff --git a/src/share/classes/sun/applet/AppletViewerPanel.java b/src/share/classes/sun/applet/AppletViewerPanel.java --- a/src/share/classes/sun/applet/AppletViewerPanel.java +++ b/src/share/classes/sun/applet/AppletViewerPanel.java @@ -59,7 +59,7 @@ /** * The attributes of the applet. */ - Hashtable atts; + Hashtable atts; /* * JDK 1.1 serialVersionUID @@ -69,7 +69,7 @@ /** * Construct an applet viewer and start the applet. */ - AppletViewerPanel(URL documentURL, Hashtable atts) { + AppletViewerPanel(URL documentURL, Hashtable atts) { this.documentURL = documentURL; this.atts = atts; @@ -105,7 +105,7 @@ * Get an applet parameter. */ public String getParameter(String name) { - return (String)atts.get(name.toLowerCase()); + return atts.get(name.toLowerCase()); } /** diff --git a/src/share/classes/sun/applet/Main.java b/src/share/classes/sun/applet/Main.java --- a/src/share/classes/sun/applet/Main.java +++ b/src/share/classes/sun/applet/Main.java @@ -84,7 +84,7 @@ /** * The list of valid URLs passed in to AppletViewer. */ - private static Vector urlList = new Vector(1); + private static Vector urlList = new Vector<>(1); // This is used in init(). Getting rid of this is desirable but depends // on whether the property that uses it is necessary/standard. @@ -153,7 +153,7 @@ // XXX 5/17 this parsing method should be changed/fixed so that // it doesn't do both parsing of the html file and launching of // the AppletPanel - AppletViewer.parse((URL) urlList.elementAt(i), encoding); + AppletViewer.parse(urlList.elementAt(i), encoding); } catch (IOException e) { System.err.println(lookup("main.err.io", e.getMessage())); return 1; @@ -307,10 +307,10 @@ // 2) Reflection removes any build dependency between appletviewer // and jdb. try { - Class c = Class.forName("com.sun.tools.example.debug.tty.TTY", true, + Class c = Class.forName("com.sun.tools.example.debug.tty.TTY", true, ClassLoader.getSystemClassLoader()); Method m = c.getDeclaredMethod("main", - new Class[] { String[].class }); + new Class[] { String[].class }); m.invoke(null, new Object[] { newArgs }); } catch (ClassNotFoundException cnfe) { System.err.println(lookup("main.debug.cantfinddebug")); @@ -367,7 +367,7 @@ // Read in the System properties. If something is going to be // over-written, warn about it. Properties sysProps = System.getProperties(); - for (Enumeration e = sysProps.propertyNames(); e.hasMoreElements(); ) { + for (Enumeration e = sysProps.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); String val = sysProps.getProperty(key); String oldVal;