[shrinkwrap-issues] [JBoss JIRA] (SHRINKWRAP-517) URLPackageScanner fails to close ZipFile and retains a Windows file lock

Falko Modler (JIRA) issues at jboss.org
Thu Jul 6 09:51:00 EDT 2017


    [ https://issues.jboss.org/browse/SHRINKWRAP-517?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13431571#comment-13431571 ] 

Falko Modler commented on SHRINKWRAP-517:
-----------------------------------------

The only way I found to reproduce this problem is the way the three tests mentioned above are creating a {{Domain}} via a custom {{URLClassLoader}}.
In that scenario both the CL *and* the {{ZipFile}} in the Scanner have to be closed.

This means that:
- either I cannot provide a test because tests are executed with JDK5 and in that version {{URLClassLoader}} does not have a {{.close()}} method
- or I have to use an ugly hack like this one: https://stackoverflow.com/a/31114719 (which is probably Oracle/Sun JVM specific)

PS: There are at least two more tests creating an {{URLClassLoader}} but never closing it.

> URLPackageScanner fails to close ZipFile and retains a Windows file lock
> ------------------------------------------------------------------------
>
>                 Key: SHRINKWRAP-517
>                 URL: https://issues.jboss.org/browse/SHRINKWRAP-517
>             Project: ShrinkWrap
>          Issue Type: Bug
>          Components: impl-base
>    Affects Versions: 1.2.6
>            Reporter: Falko Modler
>
> The method {{org.jboss.shrinkwrap.impl.base.URLPackageScanner.handleArchiveByFile(File)}} creates a {{ZipFile}} but never closes it:
> {code:java}
>     private void handleArchiveByFile(File file) throws IOException, ClassNotFoundException {
>         try {
>             log.fine("archive: " + file);
>             ZipFile zip = new ZipFile(file);
>             Enumeration<? extends ZipEntry> entries = zip.entries();
>             while (entries.hasMoreElements()) {
>                 ZipEntry entry = entries.nextElement();
>                 String name = entry.getName();
>                 if (name.startsWith(prefix + packageNamePath) && name.endsWith(SUFFIX_CLASS)
>                         && (addRecursively || !name.substring((prefix + packageNamePath).length() + 1).contains("/"))) {
>                     String className = name.replace("/", ".").substring(prefix.length(), name.length() - SUFFIX_CLASS.length());
>                     foundClass(className, name );
>                 }
>             }
>         } catch (ZipException e) {
>             throw new RuntimeException("Error handling file " + file, e);
>         }
>     }
> {code}
> Solution: Close {{zip}} in {{finally}}.
> I found this problem with the help of Eclipse (which showed warning "Resource leak: 'zip' is never closed") while analyzing [why three tests are unable to delete the test archive|https://github.com/shrinkwrap/shrinkwrap/pull/109#discussion_r125745011].
> Besides the fix in {{URLPackageScanner}} we need one more change to enable the deletion of the test archive in those tests: All three tests create a cusom {{URLClassLoader}} but they never close it.
> Unfortunately, {{java.net.URLClassLoader.close()}} is a JDK7+ feature but the tests are executed with JDK5.



--
This message was sent by Atlassian JIRA
(v7.2.3#72005)


More information about the shrinkwrap-issues mailing list