TAP5-2448: URLClassLoader did not implement Closable before Java 7, use the current thread's context ClassLoader
diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
index a05b2bc..e8076b2 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/AbstractResource.java
@@ -12,7 +12,6 @@
package org.apache.tapestry5.ioc.internal.util;
-import org.apache.commons.io.IOUtils;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.util.LocalizedNameGenerator;
@@ -22,7 +21,6 @@
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
-import java.net.URLClassLoader;
import java.util.List;
import java.util.Locale;
@@ -284,33 +282,21 @@
}
if ("jar".equals(url.getProtocol())){
- URLClassLoader classLoaderWithJar = null;
- try
+ // TAP5-2448: make sure that the URL does not reference a directory
+ String urlAsString = url.toString();
+
+ int indexOfExclamationMark = url.toString().indexOf('!');
+
+ String resourceInJar = urlAsString.substring(indexOfExclamationMark + 2);
+
+ boolean isDirectory = Thread.currentThread().getContextClassLoader().getResource(resourceInJar + "/") != null;
+
+ if (isDirectory)
{
-
- // TAP5-2448: make sure that the URL does not reference a directory
- String urlAsString = url.toString();
-
- int indexOfExclamationMark = url.toString().indexOf('!');
-
- String jarFile = urlAsString.substring(4, indexOfExclamationMark);
- String resourceInJar = urlAsString.substring(indexOfExclamationMark + 2);
-
- classLoaderWithJar = new URLClassLoader(new URL[]{ new URL(jarFile) });
-
- boolean isDirectory = classLoaderWithJar.getResource(resourceInJar + "/") != null;
-
- classLoaderWithJar.close();
-
- if (isDirectory)
- {
- throw new IOException("Cannot open a steam for a resource that references a directory inside a JAR file (" + url + ").");
- }
- } finally
- {
- IOUtils.closeQuietly(classLoaderWithJar);
+ throw new IOException("Cannot open a steam for a resource that references a directory inside a JAR file (" + url + ").");
}
+
}
return new BufferedInputStream(url.openStream());