From: markt Date: Sat, 27 Dec 2008 14:05:50 +0000 (+0000) Subject: Generics for o.a.c.loader X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f11e4a0217704205bbf38b3d91cff7720024f3cc;p=tomcat7.0 Generics for o.a.c.loader Fix various eclipse warnings (remove unused code, fix possible NPE) git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@729634 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/loader/ResourceEntry.java b/java/org/apache/catalina/loader/ResourceEntry.java index 6449d1cc0..b4098a773 100644 --- a/java/org/apache/catalina/loader/ResourceEntry.java +++ b/java/org/apache/catalina/loader/ResourceEntry.java @@ -47,7 +47,7 @@ public class ResourceEntry { /** * Loaded class. */ - public Class loadedClass = null; + public Class loadedClass = null; /** diff --git a/java/org/apache/catalina/loader/WebappClassLoader.java b/java/org/apache/catalina/loader/WebappClassLoader.java index 28c93d3cc..5a911453b 100644 --- a/java/org/apache/catalina/loader/WebappClassLoader.java +++ b/java/org/apache/catalina/loader/WebappClassLoader.java @@ -50,6 +50,7 @@ import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.jar.Attributes.Name; +import javax.naming.Binding; import javax.naming.NameClassPair; import javax.naming.NamingEnumeration; import javax.naming.NamingException; @@ -114,7 +115,7 @@ public class WebappClassLoader Boolean.valueOf(System.getProperty("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES", "true")).booleanValue(); protected class PrivilegedFindResource - implements PrivilegedAction { + implements PrivilegedAction { protected File file; protected String path; @@ -124,7 +125,7 @@ public class WebappClassLoader this.path = path; } - public Object run() { + public ResourceEntry run() { return findResourceInternal(file, path); } @@ -239,13 +240,13 @@ public class WebappClassLoader * The cache of ResourceEntry for classes and resources we have loaded, * keyed by resource name. */ - protected HashMap resourceEntries = new HashMap(); + protected HashMap resourceEntries = new HashMap(); /** * The list of not found resources. */ - protected HashMap notFoundResources = new HashMap(); + protected HashMap notFoundResources = new HashMap(); /** @@ -331,7 +332,8 @@ public class WebappClassLoader * A list of read File and Jndi Permission's required if this loader * is for a web application context. */ - protected ArrayList permissionList = new ArrayList(); + protected ArrayList permissionList = + new ArrayList(); /** @@ -344,7 +346,7 @@ public class WebappClassLoader * The PermissionCollection for each CodeSource for a web * application context. */ - protected HashMap loaderPC = new HashMap(); + protected HashMap loaderPC = new HashMap(); /** @@ -706,7 +708,7 @@ public class WebappClassLoader */ public String[] findRepositories() { - return ((String[])repositories.clone()); + return (repositories.clone()); } @@ -755,10 +757,11 @@ public class WebappClassLoader if (getJarPath() != null) { try { - NamingEnumeration enumeration = resources.listBindings(getJarPath()); + NamingEnumeration enumeration = + resources.listBindings(getJarPath()); int i = 0; while (enumeration.hasMoreElements() && (i < length)) { - NameClassPair ncPair = (NameClassPair) enumeration.nextElement(); + NameClassPair ncPair = enumeration.nextElement(); String name = ncPair.getName(); // Ignore non JARs present in the lib folder if (!name.endsWith(".jar")) @@ -773,8 +776,7 @@ public class WebappClassLoader } if (enumeration.hasMoreElements()) { while (enumeration.hasMoreElements()) { - NameClassPair ncPair = - (NameClassPair) enumeration.nextElement(); + NameClassPair ncPair = enumeration.nextElement(); String name = ncPair.getName(); // Additional non-JAR files are allowed if (name.endsWith(".jar")) { @@ -853,7 +855,7 @@ public class WebappClassLoader * * @exception ClassNotFoundException if the class was not found */ - public Class findClass(String name) throws ClassNotFoundException { + public Class findClass(String name) throws ClassNotFoundException { if (log.isDebugEnabled()) log.debug(" findClass(" + name + ")"); @@ -881,7 +883,7 @@ public class WebappClassLoader // Ask our superclass to locate this class, if possible // (throws ClassNotFoundException if it is not found) - Class clazz = null; + Class clazz = null; try { if (log.isTraceEnabled()) log.trace(" findClassInternal(" + name + ")"); @@ -926,7 +928,7 @@ public class WebappClassLoader if (log.isTraceEnabled()) log.debug(" Returning class " + clazz); - if ((log.isTraceEnabled()) && (clazz != null)) { + if (log.isTraceEnabled()) { ClassLoader cl; if (Globals.IS_SECURITY_ENABLED){ cl = AccessController.doPrivileged( @@ -955,7 +957,7 @@ public class WebappClassLoader URL url = null; - ResourceEntry entry = (ResourceEntry) resourceEntries.get(name); + ResourceEntry entry = resourceEntries.get(name); if (entry == null) { entry = findResourceInternal(name, name); } @@ -986,12 +988,12 @@ public class WebappClassLoader * * @exception IOException if an input/output error occurs */ - public Enumeration findResources(String name) throws IOException { + public Enumeration findResources(String name) throws IOException { if (log.isDebugEnabled()) log.debug(" findResources(" + name + ")"); - Vector result = new Vector(); + Vector result = new Vector(); int jarFilesLength = jarFiles.length; int repositoriesLength = repositories.length; @@ -1035,7 +1037,7 @@ public class WebappClassLoader // Adding the results of a call to the superclass if (hasExternalRepositories) { - Enumeration otherResourcePaths = super.findResources(name); + Enumeration otherResourcePaths = super.findResources(name); while (otherResourcePaths.hasMoreElements()) { result.addElement(otherResourcePaths.nextElement()); @@ -1097,7 +1099,7 @@ public class WebappClassLoader // Locating the repository for special handling in the case // of a JAR if (antiJARLocking) { - ResourceEntry entry = (ResourceEntry) resourceEntries.get(name); + ResourceEntry entry = resourceEntries.get(name); try { String repository = entry.codeBase.toString(); if ((repository.endsWith(".jar")) @@ -1188,7 +1190,7 @@ public class WebappClassLoader if (hasExternalRepositories && (stream == null)) stream = url.openStream(); } catch (IOException e) { - ; // Ignore + // Ignore } if (stream != null) return (stream); @@ -1227,7 +1229,7 @@ public class WebappClassLoader * * @exception ClassNotFoundException if the class was not found */ - public Class loadClass(String name) throws ClassNotFoundException { + public Class loadClass(String name) throws ClassNotFoundException { return (loadClass(name, false)); @@ -1259,12 +1261,12 @@ public class WebappClassLoader * * @exception ClassNotFoundException if the class was not found */ - public Class loadClass(String name, boolean resolve) + public Class loadClass(String name, boolean resolve) throws ClassNotFoundException { if (log.isDebugEnabled()) log.debug("loadClass(" + name + ", " + resolve + ")"); - Class clazz = null; + Class clazz = null; // Log access to stopped classloader if (!started) { @@ -1342,7 +1344,7 @@ public class WebappClassLoader return (clazz); } } catch (ClassNotFoundException e) { - ; + // Ignore } } @@ -1359,7 +1361,7 @@ public class WebappClassLoader return (clazz); } } catch (ClassNotFoundException e) { - ; + // Ignore } // (3) Delegate to parent unconditionally @@ -1379,7 +1381,7 @@ public class WebappClassLoader return (clazz); } } catch (ClassNotFoundException e) { - ; + // Ignore } } @@ -1401,12 +1403,12 @@ public class WebappClassLoader String codeUrl = codeSource.getLocation().toString(); PermissionCollection pc; - if ((pc = (PermissionCollection)loaderPC.get(codeUrl)) == null) { + if ((pc = loaderPC.get(codeUrl)) == null) { pc = super.getPermissions(codeSource); if (pc != null) { - Iterator perms = permissionList.iterator(); + Iterator perms = permissionList.iterator(); while (perms.hasNext()) { - Permission p = (Permission)perms.next(); + Permission p = perms.next(); pc.add(p); } loaderPC.put(codeUrl,pc); @@ -1602,9 +1604,9 @@ public class WebappClassLoader protected void clearReferences() { // Unregister any JDBC drivers loaded by this classloader - Enumeration drivers = DriverManager.getDrivers(); + Enumeration drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { - Driver driver = (Driver) drivers.nextElement(); + Driver driver = drivers.nextElement(); if (driver.getClass().getClassLoader() == this) { try { DriverManager.deregisterDriver(driver); @@ -1617,11 +1619,11 @@ public class WebappClassLoader // Null out any static or final fields from loaded classes, // as a workaround for apparent garbage collection bugs if (ENABLE_CLEAR_REFERENCES) { - Iterator loadedClasses = ((HashMap) resourceEntries.clone()).values().iterator(); + Iterator loadedClasses = ((HashMap) resourceEntries.clone()).values().iterator(); while (loadedClasses.hasNext()) { - ResourceEntry entry = (ResourceEntry) loadedClasses.next(); + ResourceEntry entry = loadedClasses.next(); if (entry.loadedClass != null) { - Class clazz = entry.loadedClass; + Class clazz = entry.loadedClass; try { Field[] fields = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { @@ -1695,7 +1697,7 @@ public class WebappClassLoader } else { Object value = field.get(instance); if (null != value) { - Class valueClass = value.getClass(); + Class valueClass = value.getClass(); if (!loadedByThisOrChild(valueClass)) { if (log.isDebugEnabled()) { log.debug("Not setting field " + field.getName() + @@ -1729,7 +1731,7 @@ public class WebappClassLoader * Determine whether a class was loaded by this class loader or one of * its child class loaders. */ - protected boolean loadedByThisOrChild(Class clazz) + protected boolean loadedByThisOrChild(Class clazz) { boolean result = false; for (ClassLoader classLoader = clazz.getClassLoader(); @@ -1771,7 +1773,7 @@ public class WebappClassLoader * * @return the loaded class, or null if the class isn't found */ - protected Class findClassInternal(String name) + protected Class findClassInternal(String name) throws ClassNotFoundException { if (!validate(name)) @@ -1787,7 +1789,7 @@ public class WebappClassLoader if (entry == null) throw new ClassNotFoundException(name); - Class clazz = entry.loadedClass; + Class clazz = entry.loadedClass; if (clazz != null) return clazz; @@ -1900,7 +1902,7 @@ public class WebappClassLoader if ((name == null) || (path == null)) return null; - ResourceEntry entry = (ResourceEntry) resourceEntries.get(name); + ResourceEntry entry = resourceEntries.get(name); if (entry != null) return entry; @@ -1929,9 +1931,9 @@ public class WebappClassLoader // Note : Not getting an exception here means the resource was // found if (securityManager != null) { - PrivilegedAction dp = + PrivilegedAction dp = new PrivilegedFindResource(files[i], path); - entry = (ResourceEntry)AccessController.doPrivileged(dp); + entry = AccessController.doPrivileged(dp); } else { entry = findResourceInternal(files[i], path); } @@ -2025,10 +2027,10 @@ public class WebappClassLoader File resourceFile = new File (loaderDir, jarEntry.getName()); if (!resourceFile.exists()) { - Enumeration entries = jarFiles[i].entries(); + Enumeration entries = + jarFiles[i].entries(); while (entries.hasMoreElements()) { - JarEntry jarEntry2 = - (JarEntry) entries.nextElement(); + JarEntry jarEntry2 = entries.nextElement(); if (!(jarEntry2.isDirectory()) && (!jarEntry2.getName().endsWith (".class"))) { @@ -2129,7 +2131,7 @@ public class WebappClassLoader // Ensures that all the threads which may be in a race to load // a particular class all end up with the same ResourceEntry // instance - ResourceEntry entry2 = (ResourceEntry) resourceEntries.get(name); + ResourceEntry entry2 = resourceEntries.get(name); if (entry2 == null) { resourceEntries.put(name, entry); } else { @@ -2174,7 +2176,7 @@ public class WebappClassLoader */ protected InputStream findLoadedResource(String name) { - ResourceEntry entry = (ResourceEntry) resourceEntries.get(name); + ResourceEntry entry = resourceEntries.get(name); if (entry != null) { if (entry.binaryContent != null) return new ByteArrayInputStream(entry.binaryContent); @@ -2191,9 +2193,9 @@ public class WebappClassLoader * * @param name Name of the resource to return */ - protected Class findLoadedClass0(String name) { + protected Class findLoadedClass0(String name) { - ResourceEntry entry = (ResourceEntry) resourceEntries.get(name); + ResourceEntry entry = resourceEntries.get(name); if (entry != null) { return entry.loadedClass; } @@ -2287,7 +2289,7 @@ public class WebappClassLoader return (true); JarFile jarFile = new JarFile(jarfile); for (int i = 0; i < triggers.length; i++) { - Class clazz = null; + Class clazz = null; try { if (parent != null) { clazz = parent.loadClass(triggers[i]); @@ -2332,7 +2334,7 @@ public class WebappClassLoader if(encoded) { return getURI(realFile); } else { - return realFile.toURL(); + return realFile.toURI().toURL(); } } diff --git a/java/org/apache/catalina/loader/WebappLoader.java b/java/org/apache/catalina/loader/WebappLoader.java index cdc7fcb15..753b995d8 100644 --- a/java/org/apache/catalina/loader/WebappLoader.java +++ b/java/org/apache/catalina/loader/WebappLoader.java @@ -49,7 +49,6 @@ import javax.servlet.ServletContext; import org.apache.catalina.Container; import org.apache.catalina.Context; -import org.apache.catalina.Engine; import org.apache.catalina.Globals; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; @@ -207,7 +206,7 @@ public class WebappLoader /** * Repositories that are set in the loader, for JMX. */ - private ArrayList loaderRepositories = null; + private ArrayList loaderRepositories = null; // ------------------------------------------------------------- Properties @@ -218,7 +217,7 @@ public class WebappLoader */ public ClassLoader getClassLoader() { - return ((ClassLoader) classLoader); + return classLoader; } @@ -423,12 +422,12 @@ public class WebappLoader */ public String[] findRepositories() { - return ((String[])repositories.clone()); + return repositories.clone(); } public String[] getRepositories() { - return ((String[])repositories.clone()); + return repositories.clone(); } /** Extra repositories for this loader @@ -564,7 +563,6 @@ public class WebappLoader // Register ourself. The container must be a webapp try { StandardContext ctx=(StandardContext)container; - Engine eng=(Engine)ctx.getParent().getParent(); String path = ctx.getPath(); if (path.equals("")) { path = "/"; @@ -652,15 +650,13 @@ public class WebappLoader setPermissions(); - if (classLoader instanceof Lifecycle) - ((Lifecycle) classLoader).start(); + ((Lifecycle) classLoader).start(); // Binding the Webapp class loader to the directory context - DirContextURLStreamHandler.bind - ((ClassLoader) classLoader, this.container.getResources()); + DirContextURLStreamHandler.bind(classLoader, + this.container.getResources()); StandardContext ctx=(StandardContext)container; - Engine eng=(Engine)ctx.getParent().getParent(); String path = ctx.getPath(); if (path.equals("")) { path = "/"; @@ -703,13 +699,11 @@ public class WebappLoader } // Throw away our current class loader - if (classLoader instanceof Lifecycle) - ((Lifecycle) classLoader).stop(); - DirContextURLStreamHandler.unbind((ClassLoader) classLoader); + ((Lifecycle) classLoader).stop(); + DirContextURLStreamHandler.unbind(classLoader); try { StandardContext ctx=(StandardContext)container; - Engine eng=(Engine)ctx.getParent().getParent(); String path = ctx.getPath(); if (path.equals("")) { path = "/"; @@ -742,7 +736,6 @@ public class WebappLoader // Validate the source of this event if (!(event.getSource() instanceof Context)) return; - Context context = (Context) event.getSource(); // Process a relevant property change if (event.getPropertyName().equals("reloadable")) { @@ -767,15 +760,15 @@ public class WebappLoader private WebappClassLoader createClassLoader() throws Exception { - Class clazz = Class.forName(loaderClass); + Class clazz = Class.forName(loaderClass); WebappClassLoader classLoader = null; if (parentClassLoader == null) { parentClassLoader = container.getParentClassLoader(); } - Class[] argTypes = { ClassLoader.class }; + Class[] argTypes = { ClassLoader.class }; Object[] args = { parentClassLoader }; - Constructor constr = clazz.getConstructor(argTypes); + Constructor constr = clazz.getConstructor(argTypes); classLoader = (WebappClassLoader) constr.newInstance(args); return classLoader; @@ -887,7 +880,7 @@ public class WebappLoader if (servletContext == null) return; - loaderRepositories=new ArrayList(); + loaderRepositories=new ArrayList(); // Loading the work directory File workDir = (File) servletContext.getAttribute(Globals.WORK_DIR_ATTR); @@ -895,7 +888,7 @@ public class WebappLoader log.info("No work dir for " + servletContext); } - if( log.isDebugEnabled()) + if( log.isDebugEnabled() && workDir != null) log.debug(sm.getString("webappLoader.deploy", workDir.getAbsolutePath())); classLoader.setWorkDir(workDir); @@ -981,10 +974,11 @@ public class WebappLoader // Looking up directory /WEB-INF/lib in the context try { - NamingEnumeration enumeration = resources.listBindings(libPath); + NamingEnumeration enumeration = + resources.listBindings(libPath); while (enumeration.hasMoreElements()) { - Binding binding = (Binding) enumeration.nextElement(); + Binding binding = enumeration.nextElement(); String filename = libPath + "/" + binding.getName(); if (!filename.endsWith(".jar")) continue; @@ -1139,10 +1133,9 @@ public class WebappLoader try { - NamingEnumeration enumeration = srcDir.list(""); + NamingEnumeration enumeration = srcDir.list(""); while (enumeration.hasMoreElements()) { - NameClassPair ncPair = - (NameClassPair) enumeration.nextElement(); + NameClassPair ncPair = enumeration.nextElement(); String name = ncPair.getName(); Object object = srcDir.lookup(name); File currentFile = new File(destDir, name); @@ -1201,16 +1194,11 @@ public class WebappLoader org.apache.juli.logging.LogFactory.getLog( WebappLoader.class ); private ObjectName oname; - private MBeanServer mserver; - private String domain; private ObjectName controller; public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { oname=name; - mserver=server; - domain=name.getDomain(); - return name; }