kamranzafar / JCL

Jar Class Loader, a configurable and dynamic custom classloader designed to create, manage and manipulate isolated Java classloaders in IoC frameworks and web applications.
http://kamranzafar.github.com/
579 stars 161 forks source link

Dealing with java.net.MalformedURLException: Nested JAR URLs are not supported #74

Open dgrandemange opened 3 years ago

dgrandemange commented 3 years ago

JCL version used : 2.7

Let's say I have a fatjar (webapp with jetty inside) webapp-fat.jar, which internally includes an api.jar, which itself includes an api-impl.jar and uses JCL to load classes and resources from it through its specific classloader.

When a class of api-impl.jar tries to load one of its internal resource (say some .properties or .xml), JCL's JarResources.getResourceURL(...) is invoked, which delegates to URL(...) constructor, which in turn delegates to sun's sun.net.www.protocol.jar.Handler.parseURL(URL, String, int, int).

This was working well Java 8u221. but since Java8u241, Sun's sun.net.www.protocol.jar.Handler.parseURL(URL, String, int, int) raises the following exception :

java.net.MalformedURLException: Nested JAR URLs are not supported complaining that nested JAR URLs are not supported any more.

Indeed, when looking at the URL given to sun.net.www.protocol.jar.Handler.parseURL(...), the resource URL looks like this :

jar:jar:file:/webapp-fat.jar-_ws-any-/webapp/WEB-INF/lib/api.jar!/api-impl.jar!/some-api-impl-resource.xml

Does JCL provide a way to deal with such case ?

See also this stackoverflow topic : MalformedURLException in Java JDK 8 when trying to create an URL