You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2018/11/02 11:24:50 UTC

svn commit: r1845573 - in /tomcat/trunk: java/org/apache/catalina/loader/WebappClassLoaderBase.java webapps/docs/changelog.xml

Author: markt
Date: Fri Nov  2 11:24:50 2018
New Revision: 1845573

URL: http://svn.apache.org/viewvc?rev=1845573&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62868
Order the Enumeration<URL> provided by WebappClassLoaderBase.getResources(String) according to the setting of the delegate flag.

Modified:
    tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java?rev=1845573&r1=1845572&r2=1845573&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java Fri Nov  2 11:24:50 2018
@@ -51,6 +51,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.NoSuchElementException;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -1047,6 +1048,24 @@ public abstract class WebappClassLoaderB
     }
 
 
+    @Override
+    public Enumeration<URL> getResources(String name) throws IOException {
+
+        Enumeration<URL> parentResources = getParent().getResources(name);
+        Enumeration<URL> localResources = findResources(name);
+
+        // Need to combine these enumerations. The order in which the
+        // Enumerations are combined depends on how delegation is configured
+        boolean delegateFirst = delegate || filter(name, false);
+
+        if (delegateFirst) {
+            return new CombinedEnumeration(parentResources, localResources);
+        } else {
+            return new CombinedEnumeration(localResources, parentResources);
+        }
+    }
+
+
     /**
      * Find the resource with the given name, and return an input stream
      * that can be used for reading it.  The search order is as described
@@ -2600,4 +2619,43 @@ public abstract class WebappClassLoaderB
             return Boolean.valueOf(findResource("logging.properties") != null);
         }
     }
+
+
+    private static class CombinedEnumeration implements Enumeration<URL> {
+
+        private final Enumeration<URL>[] sources;
+        private int index = 0;
+
+        public CombinedEnumeration(Enumeration<URL> enum1, Enumeration<URL> enum2) {
+            @SuppressWarnings("unchecked")
+            Enumeration<URL>[] sources = new Enumeration[] { enum1, enum2 };
+            this.sources = sources;
+        }
+
+
+        @Override
+        public boolean hasMoreElements() {
+            return inc();
+        }
+
+
+        @Override
+        public URL nextElement() {
+            if (inc()) {
+                return sources[index].nextElement();
+            }
+            throw new NoSuchElementException();
+        }
+
+
+        private boolean inc() {
+            while (index < sources.length) {
+                if (sources[index].hasMoreElements()) {
+                    return true;
+                }
+                index++;
+            }
+            return false;
+        }
+    }
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1845573&r1=1845572&r2=1845573&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Nov  2 11:24:50 2018
@@ -147,6 +147,11 @@
         Correct a typo in the Spanish resource files. Patch provided by Diego
         Agulló. (markt)
       </fix>
+      <fix>
+        <bug>62868</bug>: Order the <code>Enumeration&lt;URL&gt;</code> provided
+        by <code>WebappClassLoaderBase.getResources(String)</code> according to
+        the setting of the delegate flag. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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