From 61aeaaf89164aa93280527c7eb80cf4c1432fbee Mon Sep 17 00:00:00 2001 From: Andrew John Hughes Date: Thu, 21 Oct 2010 21:12:21 +0100 Subject: Fix most warnings arising from NetX code. 2010-10-20 Andrew John Hughes * netx/javax/jnlp/ServiceManager.java: (lookupTable): Add generic types. * netx/net/sourceforge/jnlp/AppletDesc.java: (parameters): Likewise. (AppletDesc(String,String,URL,int,int,Map)): Likewise. (getParameters()): Likewise. * netx/net/sourceforge/jnlp/ApplicationDesc.java: (getArguments()): Remove redundant cast. (addArgument(String)): Add generic typing. * netx/net/sourceforge/jnlp/ExtensionDesc.java: (extToPart): Add generic types. (eagerExtParts): Likewise. * netx/net/sourceforge/jnlp/InformationDesc.java: (info): Likewise. (getIcons(Object)): Add generic typing. (getAssociations()): Likewise. (getRelatedContents()): Likewise. (getItem(Object)): Likewise. (getItems(Object)): Likewise. (addItem(String,Object)): Likewise. * netx/net/sourceforge/jnlp/JNLPFile.java: (resources): Likewise. (InformationDesc.getItems(Object)): Likewise. (getResources(Class)): Likewise. * netx/net/sourceforge/jnlp/LaunchException.java: (getCauses()): Likewise. * netx/net/sourceforge/jnlp/Launcher.java: (launchApplication(JNLPFile)): Likewise. * netx/net/sourceforge/jnlp/NetxPanel.java: (NetxPanel(URL,Hashtable)): Likewise. (NetxPanel(URL,Hashtable,boolean)): Likewise. * netx/net/sourceforge/jnlp/Node.java: (getChildNodes()): Likewise. * netx/net/sourceforge/jnlp/Parser.java: (getResources(Node,boolean)): Likewise. (getInfo(Node)): Likewise. (getInformationDesc(Node)): Likewise. (getApplet(Node)): Likewise. (getApplication(Node)): Likewise. (splitString(String)): Likewise. (getLocales(Node)): Likewise. (getChildNodes(Node,String)): Likewise. * netx/net/sourceforge/jnlp/PluginBridge.java: Fix variable naming and add generic types. (cacheJars): Changed from cache_jars. (cacheExJars): Changed from cache_ex-jars. (atts): Add generic typing. (PluginBridge(URL,URL,String,String,int,int,Hashtable)): Likewise. (getInformation(Locale)): Likewise. (getResources(Locale,String,String)): Likewise. (getJARs()): Avoid excessive copying; filtering already performed by getResources in JNLPFile. * netx/net/sourceforge/jnlp/ResourcesDesc.java: (resources): Add generic typing. (getJREs()): Likewise. (getJARs()): Likewise. (getJARs(String)): Likewise. (getExtensions()): Likewise. (getPackages()): Likewise. (getPackages(String)): Likewise. (getProperties()): Likewise. (getPropertiesMap()): Likewise. (getResources(Class)): Make generic. * netx/net/sourceforge/jnlp/Version.java: (matches(Version)): Add generic types. (matchesAny(Version)): Likewise. (matchesSingle(String)): Likewise. (matches(String,String)): Likewise. (equal(List,List)): Likewise. (greater(List,List)): Likewise. (compare(String,String)): Use Integer.valueOf. (normalize(List,int)): Add generic types, using a List of lists rather than an array of lists. (getVersionStrings()): Add generic types. (getParts()): Likewise. * netx/net/sourceforge/jnlp/cache/CacheUtil.java: (waitForResources(ApplicationInstance,ResourceTracker, URL,String)): Likewise. * netx/net/sourceforge/jnlp/cache/DefaultDownloadIndicator.java: (getListener(ApplicatonInstance,String,URL)): Use setVisible instead of show(). (disposeListener(DownloadServiceListener)): Use setVisible instead of hide(). (DownloadPanel.urls): Add generic typing. (DownloadPanel.panels): Likewise. (DownloadPanel.update(URL,String,long,long,int)): Fix formatting. Add generic types. * netx/net/sourceforge/jnlp/cache/Resource.java: (resources): Add generic typing. (trackers): Likewise. (getResource(URL,Version,UpdatePolicy)): Use generic types. (getTracker()): Likewise. (addTracker(ResourceTracker)): Likewise. (fireDownloadEvent()): Likewise. * netx/net/sourceforge/jnlp/cache/ResourceTracker.java: (prefetchTrackers): Add generic typing. (queue): Likewise. (active): Likewise. (resources): Likewise. (listeners): Likewise. (fireDownloadEvent(Resource)): Remove unneeded cast. (getPrefetch()): Use generic typing. (selectByFlag(List,int,int)): Likewise. (getResource(URL)): Likewise. * netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java: (weakClips): Add generic types. (destroy()): Use generic typing. (getApplets()): Likewise. (getStreamKeys()): Likewise. * netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java: (weakWindows): Add generic types. (installEnvironment()): Likewise. (destroy()): Remove redundant cast. * netx/net/sourceforge/jnlp/runtime/Boot.java: Extend PrivilegedAction. (run()): Add generic typing. (getOptions(String)): Likewise. * netx/net/sourceforge/jnlp/runtime/Boot13.java: (main(String[]): Likewise. * netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java: Fix formatting. (urlToLoader): Add generic types. (resourcePermissions): Likewise. (available): Likewise. (jarEntries): Likewise. (getInstance(JNLPFile,UpdatePolicy)): Remove redundant cast. (getInstance(URL,String,Version,UpdatePolicy)): Likewise. (initializeExtensions()): Add generic types. (initializePermissions()): Likewise. (initializeResources()): Likewise. (getPermissions(CodeSource)): Likewise. (fillInPartJars(List)): Likewise. (activateJars(List)): Likewise. (loadClass(String)): Likewise. Suppress warnings due to sun.misc.JarIndex usage. (findResources(String)): Mark as overriding. Add generic types. (getExtensionName()): Add @Deprecated annotation. (getExtensionHREF()): Likewise. * netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java: (weakWindows): Add generic typing. (weakApplications): Likewise. (getApplication(Window)): Remove redundant casts. Add w, which is window cast to Window. * netx/net/sourceforge/jnlp/services/ServiceUtil.java: (invoke(Object,Method,Object[])): Use generic types. * netx/net/sourceforge/jnlp/services/XPersistenceService.java: (getNames(URL)): Likewise. * netx/net/sourceforge/jnlp/tools/JarSigner.java: (verifyJars(List,ResourceTracker)): Remove redundant cast. * netx/net/sourceforge/jnlp/util/WeakList.java: Redesign as a generic type. (refs): Add generic types. (deref(WeakReference)): Likewise. (get(int)): Likewise. (set(int,Object)): Likewise. (add(int,E)): Likewise. (remove()): Likewise. (hardList()): Likewise. * netx/net/sourceforge/nanoxml/XMLElement.java: (attributes): Add generic typing. (children): Likewise. (entities): Likewise. (XMLElement()): Use generic types. (XMLElement(Hashtable): Likewise. (resolveEntity(StringBuffer)): Remove redundant cast. --- .../jnlp/runtime/AppletEnvironment.java | 10 +-- .../jnlp/runtime/ApplicationInstance.java | 6 +- netx/net/sourceforge/jnlp/runtime/Boot.java | 8 +- netx/net/sourceforge/jnlp/runtime/Boot13.java | 4 +- .../sourceforge/jnlp/runtime/JNLPClassLoader.java | 100 +++++++++++---------- .../jnlp/runtime/JNLPSecurityManager.java | 11 +-- 6 files changed, 72 insertions(+), 67 deletions(-) (limited to 'netx/net/sourceforge/jnlp/runtime') diff --git a/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java b/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java index cd37c44..65032fe 100644 --- a/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java +++ b/netx/net/sourceforge/jnlp/runtime/AppletEnvironment.java @@ -57,7 +57,7 @@ public class AppletEnvironment implements AppletContext, AppletStub { private Container cont; /** weak references to the audio clips */ - private WeakList weakClips = new WeakList(); + private WeakList weakClips = new WeakList(); /** whether the applet has been started / displayed */ private boolean appletStarted = false; @@ -121,9 +121,9 @@ public class AppletEnvironment implements AppletContext, AppletStub { public void destroy() { destroyed = true; - List clips = weakClips.hardList(); + List clips = weakClips.hardList(); for (int i = 0; i < clips.size(); i++) { - ((AppletAudioClip)clips.get(i)).dispose(); + clips.get(i).dispose(); } } @@ -217,7 +217,7 @@ public class AppletEnvironment implements AppletContext, AppletStub { * Returns an enumeration that contains only the applet * from the JNLP file. */ - public Enumeration getApplets() { + public Enumeration getApplets() { checkDestroyed(); return Collections.enumeration( Arrays.asList(new Applet[] { applet }) ); @@ -293,7 +293,7 @@ public class AppletEnvironment implements AppletContext, AppletStub { /** * Required for JRE1.4, but not implemented yet. */ - public Iterator getStreamKeys() { + public Iterator getStreamKeys() { checkDestroyed(); return null; diff --git a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java index 95ccb1e..b5266f0 100644 --- a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java +++ b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java @@ -77,7 +77,7 @@ public class ApplicationInstance { private boolean stopped = false; /** weak list of windows opened by the application */ - private WeakList weakWindows = new WeakList(); + private WeakList weakWindows = new WeakList(); /** list of application listeners */ private EventListenerList listeners = new EventListenerList(); @@ -193,7 +193,7 @@ public class ApplicationInstance { // Add to hashmap AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] {pd}); - PrivilegedAction installProps = new PrivilegedAction() { + PrivilegedAction installProps = new PrivilegedAction() { public Object run() { for (int i=0; i < props.length; i++) { System.setProperty(props[i].getKey(), props[i].getValue()); @@ -236,7 +236,7 @@ public class ApplicationInstance { try { // destroy resources for (int i=0; i < weakWindows.size(); i++) { - Window w = (Window) weakWindows.get(i); + Window w = weakWindows.get(i); if (w != null) w.dispose(); } diff --git a/netx/net/sourceforge/jnlp/runtime/Boot.java b/netx/net/sourceforge/jnlp/runtime/Boot.java index 7442549..ea76bcb 100644 --- a/netx/net/sourceforge/jnlp/runtime/Boot.java +++ b/netx/net/sourceforge/jnlp/runtime/Boot.java @@ -58,7 +58,7 @@ import net.sourceforge.jnlp.services.ServiceUtil; * @author Jon A. Maxwell (JAM) - initial author * @version $Revision: 1.21 $ */ -public final class Boot implements PrivilegedAction { +public final class Boot implements PrivilegedAction { // todo: decide whether a spawned netx (external launch) // should inherit the same options as this instance (store argv?) @@ -199,7 +199,7 @@ public final class Boot implements PrivilegedAction { /** * The privileged part (jdk1.3 compatibility). */ - public Object run() { + public Void run() { JNLPRuntime.setBaseDir(getBaseDir()); JNLPRuntime.setSecurityEnabled(null == getOption("-nosecurity")); JNLPRuntime.initialize(true); @@ -418,7 +418,7 @@ public final class Boot implements PrivilegedAction { * returned once for each occurrence. */ private static String[] getOptions(String option) { - List result = new ArrayList(); + List result = new ArrayList(); for (int i=0; i < args.length; i++) { if (option.equals(args[i])) { @@ -433,7 +433,7 @@ public final class Boot implements PrivilegedAction { i++; } - return (String[]) result.toArray( new String[result.size()] ); + return result.toArray( new String[result.size()] ); } /** diff --git a/netx/net/sourceforge/jnlp/runtime/Boot13.java b/netx/net/sourceforge/jnlp/runtime/Boot13.java index 4440c5f..1b5aaa3 100644 --- a/netx/net/sourceforge/jnlp/runtime/Boot13.java +++ b/netx/net/sourceforge/jnlp/runtime/Boot13.java @@ -93,8 +93,8 @@ public class Boot13 extends URLClassLoader { Thread.currentThread().setContextClassLoader(b); // try to prevent getting the non-policy version of classes - Class c = b.loadClass("net.sourceforge.jnlp.runtime.Boot"); - Method main = c.getDeclaredMethod("main", new Class[] {String[].class} ); + Class c = b.loadClass("net.sourceforge.jnlp.runtime.Boot"); + Method main = c.getDeclaredMethod("main", new Class[] {String[].class} ); main.invoke(null, new Object[] { args } ); } diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java index 9ce6f46..3dc1939 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java @@ -81,7 +81,8 @@ public class JNLPClassLoader extends URLClassLoader { private static String R(String key) { return JNLPRuntime.getMessage(key); } /** map from JNLPFile url to shared classloader */ - private static Map urlToLoader = new HashMap(); // never garbage collected! + private static Map urlToLoader = + new HashMap(); // never garbage collected! /** the directory for native code */ private File nativeDir = null; // if set, some native code exists @@ -93,7 +94,7 @@ public class JNLPClassLoader extends URLClassLoader { private AccessControlContext acc = AccessController.getContext(); /** the permissions for the cached jar files */ - private List resourcePermissions; + private List resourcePermissions; /** the app */ private ApplicationInstance app = null; // here for faster lookup in security manager @@ -123,27 +124,28 @@ public class JNLPClassLoader extends URLClassLoader { private ArrayList runtimePermissions = new ArrayList(); /** all jars not yet part of classloader or active */ - private List available = new ArrayList(); + private List available = new ArrayList(); - /** all of the jar files that were verified */ - private ArrayList verifiedJars = null; + /** all of the jar files that were verified */ + private ArrayList verifiedJars = null; - /** all of the jar files that were not verified */ - private ArrayList unverifiedJars = null; + /** all of the jar files that were not verified */ + private ArrayList unverifiedJars = null; - /** the jarsigner tool to verify our jars */ - private JarSigner js = null; + /** the jarsigner tool to verify our jars */ + private JarSigner js = null; - private boolean signing = false; + private boolean signing = false; - /** ArrayList containing jar indexes for various jars available to this classloader */ - private ArrayList jarIndexes = new ArrayList(); + /** ArrayList containing jar indexes for various jars available to this classloader */ + private ArrayList jarIndexes = new ArrayList(); - /** File entries in the jar files available to this classloader */ - private TreeSet jarEntries = new TreeSet(); + /** File entries in the jar files available to this classloader */ + private TreeSet jarEntries = new TreeSet(); - /** Map of specific codesources to securitydesc */ - private HashMap jarLocationSecurityMap = new HashMap(); + /** Map of specific codesources to securitydesc */ + private HashMap jarLocationSecurityMap = + new HashMap(); /** * Create a new JNLPClassLoader from the specified file. @@ -273,7 +275,7 @@ public class JNLPClassLoader extends URLClassLoader { String uniqueKey = file.getUniqueKey(); if (uniqueKey != null) - baseLoader = (JNLPClassLoader) urlToLoader.get(uniqueKey); + baseLoader = urlToLoader.get(uniqueKey); try { @@ -286,7 +288,7 @@ public class JNLPClassLoader extends URLClassLoader { // New loader init may have caused extentions to create a // loader for this unique key. Check. - JNLPClassLoader extLoader = (JNLPClassLoader) urlToLoader.get(uniqueKey); + JNLPClassLoader extLoader = urlToLoader.get(uniqueKey); if (extLoader != null && extLoader != loader) { if (loader.signing && !extLoader.signing) @@ -328,7 +330,7 @@ public class JNLPClassLoader extends URLClassLoader { */ public static JNLPClassLoader getInstance(URL location, String uniqueKey, Version version, UpdatePolicy policy) throws IOException, ParseException, LaunchException { - JNLPClassLoader loader = (JNLPClassLoader) urlToLoader.get(uniqueKey); + JNLPClassLoader loader = urlToLoader.get(uniqueKey); if (loader == null || !location.equals(loader.getJNLPFile().getFileLocation())) loader = getInstance(new JNLPFile(location, uniqueKey, version, false, policy), policy); @@ -342,7 +344,7 @@ public class JNLPClassLoader extends URLClassLoader { void initializeExtensions() { ExtensionDesc[] ext = resources.getExtensions(); - List loaderList = new ArrayList(); + List loaderList = new ArrayList(); loaderList.add(this); @@ -359,14 +361,14 @@ public class JNLPClassLoader extends URLClassLoader { } //} - loaders = (JNLPClassLoader[]) loaderList.toArray(new JNLPClassLoader[ loaderList.size()]); + loaders = loaderList.toArray(new JNLPClassLoader[loaderList.size()]); } /** * Make permission objects for the classpath. */ void initializePermissions() { - resourcePermissions = new ArrayList(); + resourcePermissions = new ArrayList(); JARDesc jars[] = resources.getJARs(); for (int i=0; i < jars.length; i++) { @@ -398,7 +400,7 @@ public class JNLPClassLoader extends URLClassLoader { R("LCInit"), R("LFatalVerification"), "No jars!"); } */ - List initialJars = new ArrayList(); + List initialJars = new ArrayList(); for (int i=0; i < jars.length; i++) { @@ -585,7 +587,7 @@ public class JNLPClassLoader extends URLClassLoader { // add in permission to read the cached JAR files for (int i=0; i < resourcePermissions.size(); i++) - result.add((Permission) resourcePermissions.get(i)); + result.add(resourcePermissions.get(i)); // add in the permissions that the user granted. for (int i=0; i < runtimePermissions.size(); i++) @@ -603,12 +605,12 @@ public class JNLPClassLoader extends URLClassLoader { * to be loaded at the same time as the JARs specified (ie, are * in the same part). */ - protected void fillInPartJars(List jars) { + protected void fillInPartJars(List jars) { for (int i=0; i < jars.size(); i++) { - String part = ((JARDesc) jars.get(i)).getPart(); + String part = jars.get(i).getPart(); for (int a=0; a < available.size(); a++) { - JARDesc jar = (JARDesc) available.get(a); + JARDesc jar = available.get(a); if (part != null && part.equals(jar.getPart())) if (!jars.contains(jar)) @@ -625,15 +627,15 @@ public class JNLPClassLoader extends URLClassLoader { * * @param jars the list of jars to load */ - protected void activateJars(final List jars) { - PrivilegedAction activate = new PrivilegedAction() { + protected void activateJars(final List jars) { + PrivilegedAction activate = new PrivilegedAction() { - public Object run() { + public Void run() { // transfer the Jars waitForJars(jars); for (int i=0; i < jars.size(); i++) { - JARDesc jar = (JARDesc) jars.get(i); + JARDesc jar = jars.get(i); available.remove(jar); @@ -653,10 +655,9 @@ public class JNLPClassLoader extends URLClassLoader { // particularly when using The FileManager applet from Webmin. JarFile jarFile = new JarFile(localFile); - Enumeration e = jarFile.entries(); + Enumeration e = jarFile.entries(); while (e.hasMoreElements()) { - - JarEntry je = (JarEntry) e.nextElement(); + JarEntry je = e.nextElement(); // another jar in my jar? it is more likely than you think if (je.getName().endsWith(".jar")) { @@ -683,10 +684,10 @@ public class JNLPClassLoader extends URLClassLoader { is.close(); extractedJar.close(); - + // 0 byte file? skip if (fileSize <= 0) { - continue; + continue; } JarSigner signer = new JarSigner(); @@ -739,8 +740,8 @@ public class JNLPClassLoader extends URLClassLoader { // there is currently no mechanism to cache files per // instance.. so only index cached files if (localFile != null) { - JarIndex index = JarIndex.getJarIndex(new JarFile(localFile.getAbsolutePath()), null); - + JarIndex index = JarIndex.getJarIndex(new JarFile(localFile.getAbsolutePath()), + null); if (index != null) jarIndexes.add(index); } @@ -945,9 +946,9 @@ public class JNLPClassLoader extends URLClassLoader { * classloader, or one of the classloaders for the JNLP file's * extensions. */ - public Class loadClass(String name) throws ClassNotFoundException { + public Class loadClass(String name) throws ClassNotFoundException { - Class result = findLoadedClassAll(name); + Class result = findLoadedClassAll(name); // try parent classloader if (result == null) { @@ -975,7 +976,9 @@ public class JNLPClassLoader extends URLClassLoader { // Currently this loads jars directly from the site. We cannot cache it because this // call is initiated from within the applet, which does not have disk read/write permissions for (JarIndex index: jarIndexes) { - LinkedList jarList = index.get(name.replace('.', '/')); + // Non-generic code in sun.misc.JarIndex + @SuppressWarnings("unchecked") + LinkedList jarList = index.get(name.replace('.', '/')); if (jarList != null) { for (String jarName: jarList) { @@ -1090,11 +1093,12 @@ public class JNLPClassLoader extends URLClassLoader { * Finds the resource in this, the parent, or the extension * class loaders. */ - public Enumeration findResources(String name) throws IOException { - Vector resources = new Vector(); + @Override + public Enumeration findResources(String name) throws IOException { + Vector resources = new Vector(); for (int i=0; i < loaders.length; i++) { - Enumeration e; + Enumeration e; if (loaders[i] == this) e = super.findResources(name); @@ -1151,13 +1155,11 @@ public class JNLPClassLoader extends URLClassLoader { } // add jar - List jars = new ArrayList(); + List jars = new ArrayList(); jars.add(available.get(0)); fillInPartJars(jars); - - - activateJars(jars); + activateJars(jars); return this; } @@ -1166,6 +1168,7 @@ public class JNLPClassLoader extends URLClassLoader { /** * @deprecated */ + @Deprecated public String getExtensionName() { String result = file.getInformation().getTitle(); @@ -1182,6 +1185,7 @@ public class JNLPClassLoader extends URLClassLoader { /** * @deprecated */ + @Deprecated public String getExtensionHREF() { return file.getFileLocation().toString(); } diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java b/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java index 3934607..a143edb 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java @@ -98,10 +98,11 @@ class JNLPSecurityManager extends AWTSecurityManager { new SecurityException(JNLPRuntime.getMessage("RShutdown")); /** weak list of windows created */ - private WeakList weakWindows = new WeakList(); + private WeakList weakWindows = new WeakList(); /** weak list of applications corresponding to window list */ - private WeakList weakApplications = new WeakList(); + private WeakList weakApplications = + new WeakList(); /** weak reference to most app who's windows was most recently activated */ private WeakReference activeApplication = null; @@ -182,14 +183,14 @@ class JNLPSecurityManager extends AWTSecurityManager { */ protected ApplicationInstance getApplication(Window window) { for (int i = weakWindows.size(); i-->0;) { - Window w = (Window) weakWindows.get(i); + Window w = weakWindows.get(i); if (w == null) { weakWindows.remove(i); weakApplications.remove(i); } if (w == window) - return (ApplicationInstance) weakApplications.get(i); + return weakApplications.get(i); } return null; @@ -436,7 +437,7 @@ class JNLPSecurityManager extends AWTSecurityManager { if (JNLPRuntime.isDebug()) System.err.println("SM: app: "+app.getTitle()+" is adding a window: "+window); - weakWindows.add(window); // for mapping window -> app + weakWindows.add(w); // for mapping window -> app weakApplications.add(app); app.addWindow(w); -- cgit v1.2.3