From 0ecd4771f39a921b6dd3bcb5bb5db7d142c3de6e Mon Sep 17 00:00:00 2001 From: markt Date: Sat, 3 Oct 2009 19:36:01 +0000 Subject: [PATCH] Ignore duplicate entries on the classpath. Patch could be smaller but change variable name to make new behaviour clear git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@821397 13f79535-47bb-0310-9956-ffa450edef68 --- .../catalina/startup/ClassLoaderFactory.java | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/java/org/apache/catalina/startup/ClassLoaderFactory.java b/java/org/apache/catalina/startup/ClassLoaderFactory.java index d140dae42..d10b1e42e 100644 --- a/java/org/apache/catalina/startup/ClassLoaderFactory.java +++ b/java/org/apache/catalina/startup/ClassLoaderFactory.java @@ -21,7 +21,8 @@ package org.apache.catalina.startup; import java.io.File; import java.net.URL; -import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.Set; import org.apache.catalina.loader.StandardClassLoader; import org.apache.juli.logging.Log; @@ -84,7 +85,7 @@ public final class ClassLoaderFactory { log.debug("Creating new class loader"); // Construct the "class path" for this class loader - ArrayList list = new ArrayList(); + Set set = new LinkedHashSet(); // Add unpacked directories if (unpacked != null) { @@ -96,7 +97,7 @@ public final class ClassLoaderFactory { URL url = file.toURI().toURL(); if (log.isDebugEnabled()) log.debug(" Including directory " + url); - list.add(url); + set.add(url); } } @@ -116,13 +117,13 @@ public final class ClassLoaderFactory { if (log.isDebugEnabled()) log.debug(" Including jar file " + file.getAbsolutePath()); URL url = file.toURI().toURL(); - list.add(url); + set.add(url); } } } // Construct the class loader itself - URL[] array = list.toArray(new URL[list.size()]); + URL[] array = set.toArray(new URL[set.size()]); StandardClassLoader classLoader = null; if (parent == null) classLoader = new StandardClassLoader(array); @@ -157,7 +158,7 @@ public final class ClassLoaderFactory { log.debug("Creating new class loader"); // Construct the "class path" for this class loader - ArrayList list = new ArrayList(); + Set set = new LinkedHashSet(); if (locations != null && types != null && locations.length == types.length) { for (int i = 0; i < locations.length; i++) { @@ -166,7 +167,7 @@ public final class ClassLoaderFactory { URL url = new URL(location); if (log.isDebugEnabled()) log.debug(" Including URL " + url); - list.add(url); + set.add(url); } else if ( types[i] == IS_DIR ) { File directory = new File(location); directory = new File(directory.getCanonicalPath()); @@ -176,7 +177,7 @@ public final class ClassLoaderFactory { URL url = directory.toURI().toURL(); if (log.isDebugEnabled()) log.debug(" Including directory " + url); - list.add(url); + set.add(url); } else if ( types[i] == IS_JAR ) { File file=new File(location); file = new File(file.getCanonicalPath()); @@ -185,7 +186,7 @@ public final class ClassLoaderFactory { URL url = file.toURI().toURL(); if (log.isDebugEnabled()) log.debug(" Including jar file " + url); - list.add(url); + set.add(url); } else if ( types[i] == IS_GLOB ) { File directory=new File(location); if (!directory.exists() || !directory.isDirectory() || @@ -207,14 +208,14 @@ public final class ClassLoaderFactory { log.debug(" Including glob jar file " + file.getAbsolutePath()); URL url = file.toURI().toURL(); - list.add(url); + set.add(url); } } } } // Construct the class loader itself - URL[] array = list.toArray(new URL[list.size()]); + URL[] array = set.toArray(new URL[set.size()]); if (log.isDebugEnabled()) for (int i = 0; i < array.length; i++) { log.debug(" location " + i + " is " + array[i]); -- 2.11.0