You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2015/11/04 15:15:46 UTC

svn commit: r1712548 - /tomcat/trunk/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java

Author: kkolinko
Date: Wed Nov  4 14:15:46 2015
New Revision: 1712548

URL: http://svn.apache.org/viewvc?rev=1712548&view=rev
Log:
Minor fixes to TomcatURLStreamHandlerFactory in review of r1712489
1) Add a comment why List.remove() is used by r1712489
2) Simplify the code by using a for loop
3) Add null check for instance. An instance is created lazily. It is unlikely that the instance has not been created, but it is better for this cleanup method to be safe.
4) Correct javadoc typo

Modified:
    tomcat/trunk/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java

Modified: tomcat/trunk/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java?rev=1712548&r1=1712547&r2=1712548&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/TomcatURLStreamHandlerFactory.java Wed Nov  4 14:15:46 2015
@@ -19,7 +19,6 @@ package org.apache.catalina.webresources
 import java.net.URL;
 import java.net.URLStreamHandler;
 import java.net.URLStreamHandlerFactory;
-import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
@@ -100,13 +99,18 @@ public class TomcatURLStreamHandlerFacto
      * @param classLoader The class loader to release
      */
     public static void release(ClassLoader classLoader) {
-        Iterator<URLStreamHandlerFactory> iter = instance.userFactories.iterator();
-        while (iter.hasNext()) {
-            URLStreamHandlerFactory candidate = iter.next();
-            ClassLoader factoryLoader = candidate.getClass().getClassLoader();
+        if (instance == null) {
+            return;
+        }
+        List<URLStreamHandlerFactory> factories = instance.userFactories;
+        for (URLStreamHandlerFactory factory : factories) {
+            ClassLoader factoryLoader = factory.getClass().getClassLoader();
             while (factoryLoader != null) {
                 if (classLoader.equals(factoryLoader)) {
-                    instance.userFactories.remove(candidate);
+                    // Implementation note: userFactories is a
+                    // CopyOnWriteArrayList, so items are removed with
+                    // List.remove() instead of usual Iterator.remove()
+                    factories.remove(factory);
                     break;
                 }
                 factoryLoader = factoryLoader.getParent();
@@ -138,7 +142,7 @@ public class TomcatURLStreamHandlerFacto
      * applications to register their own handlers.
      *
      * @param factory The user provided factory to add to the factories Tomcat
-     *                has alredy registered
+     *                has already registered
      */
     public void addUserFactory(URLStreamHandlerFactory factory) {
         userFactories.add(factory);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org