RFR: 8211917: (zipfs) Creating or updating a JAR file system should put the MANIFEST.MF at the start

Langer, Christoph christoph.langer at sap.com
Mon Feb 17 16:26:29 UTC 2020


Hi Jaikiran, Lance,

I'm a bit late to the game. It occurred to me, whether we could maybe use the streams API to process the inodes. Something like this:

diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
--- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
+++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
@@ -56,6 +56,7 @@
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
 import java.util.regex.Pattern;
+import java.util.stream.Stream;
 import java.util.zip.CRC32;
 import java.util.zip.Deflater;
 import java.util.zip.DeflaterOutputStream;
@@ -1730,7 +1731,17 @@
             Entry e;

             // write loc
-            for (IndexNode inode : inodes.values()) {
+
+            // write the manifest inode (if any) first in the loc so that the
+            // java.util.jar.JarInputStream can find it, since it expects it to be
+            // the first or second entry in the jar
+            final IndexNode manifestInode = getInode(getBytes("/META-INF/MANIFEST.MF"));
+            final Stream<IndexNode> inodeStream = manifestInode == null ?
+                inodes.values().stream() :
+                Stream.concat(Stream.of(manifestInode),
+                    inodes.values().stream().filter(node -> !manifestInode.equals(node)));
+
+            for (IndexNode inode : (Iterable<IndexNode>)inodeStream::iterator) {
                 if (inode instanceof Entry) {    // an updated inode
                     e = (Entry)inode;
                     try {

What do you think?

I didn't have time yet to have a closer look to the testcase. Will do tomorrow.

Cheers
Christoph

> -----Original Message-----
> From: nio-dev <nio-dev-bounces at openjdk.java.net> On Behalf Of Jaikiran
> Pai
> Sent: Montag, 17. Februar 2020 03:56
> To: Lance Andersen <lance.andersen at oracle.com>
> Cc: nio-dev at openjdk.java.net; core-libs-dev at openjdk.java.net
> Subject: Re: RFR: 8211917: (zipfs) Creating or updating a JAR file system
> should put the MANIFEST.MF at the start
> 
> Hello Lance,
> 
> On 15/02/20 2:27 am, Lance Andersen wrote:
> > Hi Jaikiran,
> >
> > I think the changes to ZipFileSystem are OK.
> >
> > The test overall is good.  I am going to streamline it a bit and
> > remove the long lines (we try to keep lines to around 80 characters).
> >
> I'll keep that in mind for future changes. Thank you for taking care of
> this.
> 
> -Jaikiran



More information about the nio-dev mailing list