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

Don't close InputStream #51

Closed wizmerhill closed 7 years ago

wizmerhill commented 8 years ago

Currently if you add InputStream to jcl instance, it will close it. This is due to the use of a BufferedInputStream which on close, close underlying inputstream. This is damageable when you use a ZipInputStream which contains many different jars which has to be loaded into jcl. Jcl should not close resources give to it. Bypass is to pass a new instance of an InputStream on each ZipEntry which match jar file.

Problematic code: ` public static void loadJars(final InputStream stream) throws IOException {

final JarClassLoader jcl = new JarClassLoader();
try (ZipInputStream zip = new ZipInputStream(stream)) {
    ZipEntry entry;
    while ((entry = zip.getNextEntry()) != null) {
    final String name = entry.getName();
    if (name.matches(".*\\.jar")) {
        jcl.add(zip);
    }
    }
}

}`

kamranzafar commented 7 years ago

fixed in version 2.8