Uploaded image for project: 'ShrinkWrap'
  1. ShrinkWrap
  2. SHRINKWRAP-517

URLPackageScanner fails to close ZipFile and retains a Windows file lock

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • None
    • 1.2.6
    • impl-base
    • None
    • Hide
      • execute one of the AddPackage* tests, e.g. AddPackageFromWarTestCase (see also SHRINKWRAP-515 )
      • test[0-9]+.war will be left behind in target
      • test output will contain a warning that the test archive could not be deleted
      Show
      execute one of the AddPackage* tests, e.g. AddPackageFromWarTestCase (see also SHRINKWRAP-515 ) test [0-9] +.war will be left behind in target test output will contain a warning that the test archive could not be deleted

    Description

      The method org.jboss.shrinkwrap.impl.base.URLPackageScanner.handleArchiveByFile(File) creates a ZipFile but never closes it:

          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);
              }
          }
      

      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.

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            falko.modler@t-systems.com Falko Modler (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: