Author: markt Date: Sat Dec 27 06:05:50 2008 New Revision: 729634 URL: http://svn.apache.org/viewvc?rev=729634&view=rev Log: Generics for o.a.c.loader Fix various eclipse warnings (remove unused code, fix possible NPE)
Modified: tomcat/trunk/java/org/apache/catalina/loader/ResourceEntry.java tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Modified: tomcat/trunk/java/org/apache/catalina/loader/ResourceEntry.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/ResourceEntry.java?rev=729634&r1=729633&r2=729634&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/ResourceEntry.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/ResourceEntry.java Sat Dec 27 06:05:50 2008 @@ -47,7 +47,7 @@ /** * Loaded class. */ - public Class loadedClass = null; + public Class<?> loadedClass = null; /** Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=729634&r1=729633&r2=729634&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Sat Dec 27 06:05:50 2008 @@ -50,6 +50,7 @@ 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 @@ Boolean.valueOf(System.getProperty("org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES", "true")).booleanValue(); protected class PrivilegedFindResource - implements PrivilegedAction { + implements PrivilegedAction<ResourceEntry> { protected File file; protected String path; @@ -124,7 +125,7 @@ this.path = path; } - public Object run() { + public ResourceEntry run() { return findResourceInternal(file, path); } @@ -239,13 +240,13 @@ * The cache of ResourceEntry for classes and resources we have loaded, * keyed by resource name. */ - protected HashMap resourceEntries = new HashMap(); + protected HashMap<String, ResourceEntry> resourceEntries = new HashMap<String, ResourceEntry>(); /** * The list of not found resources. */ - protected HashMap notFoundResources = new HashMap(); + protected HashMap<String, String> notFoundResources = new HashMap<String, String>(); /** @@ -331,7 +332,8 @@ * 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<Permission> permissionList = + new ArrayList<Permission>(); /** @@ -344,7 +346,7 @@ * The PermissionCollection for each CodeSource for a web * application context. */ - protected HashMap loaderPC = new HashMap(); + protected HashMap<String, PermissionCollection> loaderPC = new HashMap<String, PermissionCollection>(); /** @@ -706,7 +708,7 @@ */ public String[] findRepositories() { - return ((String[])repositories.clone()); + return (repositories.clone()); } @@ -755,10 +757,11 @@ if (getJarPath() != null) { try { - NamingEnumeration enumeration = resources.listBindings(getJarPath()); + NamingEnumeration<Binding> 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 @@ } 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 @@ * * @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 @@ // 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 @@ 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 @@ 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 @@ * * @exception IOException if an input/output error occurs */ - public Enumeration findResources(String name) throws IOException { + public Enumeration<URL> findResources(String name) throws IOException { if (log.isDebugEnabled()) log.debug(" findResources(" + name + ")"); - Vector result = new Vector(); + Vector<URL> result = new Vector<URL>(); int jarFilesLength = jarFiles.length; int repositoriesLength = repositories.length; @@ -1035,7 +1037,7 @@ // Adding the results of a call to the superclass if (hasExternalRepositories) { - Enumeration otherResourcePaths = super.findResources(name); + Enumeration<URL> otherResourcePaths = super.findResources(name); while (otherResourcePaths.hasMoreElements()) { result.addElement(otherResourcePaths.nextElement()); @@ -1097,7 +1099,7 @@ // 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 @@ if (hasExternalRepositories && (stream == null)) stream = url.openStream(); } catch (IOException e) { - ; // Ignore + // Ignore } if (stream != null) return (stream); @@ -1227,7 +1229,7 @@ * * @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 @@ * * @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 @@ return (clazz); } } catch (ClassNotFoundException e) { - ; + // Ignore } } @@ -1359,7 +1361,7 @@ return (clazz); } } catch (ClassNotFoundException e) { - ; + // Ignore } // (3) Delegate to parent unconditionally @@ -1379,7 +1381,7 @@ return (clazz); } } catch (ClassNotFoundException e) { - ; + // Ignore } } @@ -1401,12 +1403,12 @@ 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<Permission> 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 @@ protected void clearReferences() { // Unregister any JDBC drivers loaded by this classloader - Enumeration drivers = DriverManager.getDrivers(); + Enumeration<Driver> 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 @@ // 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<ResourceEntry> loadedClasses = ((HashMap<String, ResourceEntry>) 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 @@ } else { Object value = field.get(instance); if (null != value) { - Class valueClass = value.getClass(); + Class<? extends Object> valueClass = value.getClass(); if (!loadedByThisOrChild(valueClass)) { if (log.isDebugEnabled()) { log.debug("Not setting field " + field.getName() + @@ -1729,7 +1731,7 @@ * 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<? extends Object> clazz) { boolean result = false; for (ClassLoader classLoader = clazz.getClassLoader(); @@ -1771,7 +1773,7 @@ * * @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 @@ if (entry == null) throw new ClassNotFoundException(name); - Class clazz = entry.loadedClass; + Class<?> clazz = entry.loadedClass; if (clazz != null) return clazz; @@ -1900,7 +1902,7 @@ 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 @@ // Note : Not getting an exception here means the resource was // found if (securityManager != null) { - PrivilegedAction dp = + PrivilegedAction<ResourceEntry> 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 @@ File resourceFile = new File (loaderDir, jarEntry.getName()); if (!resourceFile.exists()) { - Enumeration entries = jarFiles[i].entries(); + Enumeration<JarEntry> 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 @@ // 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 @@ */ 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 @@ * * @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 @@ 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 @@ if(encoded) { return getURI(realFile); } else { - return realFile.toURL(); + return realFile.toURI().toURL(); } } Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java?rev=729634&r1=729633&r2=729634&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Sat Dec 27 06:05:50 2008 @@ -49,7 +49,6 @@ 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 @@ /** * Repositories that are set in the loader, for JMX. */ - private ArrayList loaderRepositories = null; + private ArrayList<String> loaderRepositories = null; // ------------------------------------------------------------- Properties @@ -218,7 +217,7 @@ */ public ClassLoader getClassLoader() { - return ((ClassLoader) classLoader); + return classLoader; } @@ -423,12 +422,12 @@ */ 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 @@ // 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 @@ 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 @@ } // 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 @@ // 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 @@ 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 @@ if (servletContext == null) return; - loaderRepositories=new ArrayList(); + loaderRepositories=new ArrayList<String>(); // Loading the work directory File workDir = (File) servletContext.getAttribute(Globals.WORK_DIR_ATTR); @@ -895,7 +888,7 @@ 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 @@ // Looking up directory /WEB-INF/lib in the context try { - NamingEnumeration enumeration = resources.listBindings(libPath); + NamingEnumeration<Binding> 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 @@ try { - NamingEnumeration enumeration = srcDir.list(""); + NamingEnumeration<NameClassPair> 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 @@ 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; } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org