Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8211728

JarFile::versionedStream() does not filter META-INF resources in versioned stream

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 12
    • 12
    • core-libs
    • b15
    • Verified

    Description

      Consider a multi-release JAR with the following entries:

      META-INF/
      META-INF/MANIFEST.MF
      META-INF/foo
      META-INF/versions/
      META-INF/versions/9/
      META-INF/versions/9/META-INF/
      META-INF/versions/9/META-INF/bar

      The JarFile versionedStream() method should the ignore META-INF in the versioned section but it doesn't get it quite right and trips up on resources in the META-INF directory of the versioned stream when they don't exist in the base section. The result is that there is a null element in the stream and NPE is thrown.

      Here's a simple test to demonstrate the issue:

      echo "Multi-Release: true" > mf
      mkdir -p classes/META-INF
      touch classes/META-INF/foo
      mkdir -p classes/META-INF/versions/9/META-INF
      touch classes/META-INF/versions/9/META-INF/bar
      jar cfm foo.jar mf -C classes/ .

      cat > Test.java << EOF
      import java.io.File;
      import java.util.jar.JarEntry;
      import java.util.jar.JarFile;
      import java.util.zip.ZipFile;
      public class Test {
          public static void main(String[] args) throws Exception {
              File file = new File("foo.jar");
              try (var jarFile = new JarFile(file, true, ZipFile.OPEN_READ, Runtime.version())) {
                  jarFile.versionedStream().map(JarEntry::getRealName).forEach(System.out::println);
              }
          }
      }
      EOF
      java Test.java

      Attachments

        Activity

          People

            sherman Xueming Shen
            alanb Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: