< prev index next >
src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
Print this page
rev 57906 : 8211917: (zipfs) Creating or updating a JAR file system should put the MANIFEST.MF at the start
Reviewed-by:
@@ -1727,12 +1727,31 @@
ArrayList<Entry> elist = new ArrayList<>(inodes.size());
long written = 0;
byte[] buf = null;
Entry e;
+ final IndexNode manifestInode = getInode(getBytes("/META-INF/MANIFEST.MF"));
+ final Iterator<IndexNode> inodeIterator = inodes.values().iterator();
+ boolean manifestProcessed = false;
// write loc
- for (IndexNode inode : inodes.values()) {
+ while(inodeIterator.hasNext()) {
+ final IndexNode inode;
+ // 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
+ if (manifestInode != null && !manifestProcessed) {
+ inode = manifestInode;
+ manifestProcessed = true;
+ } else {
+ // the manifest is either absent or we have already processed it,
+ // so we pick the next inode
+ inode = inodeIterator.next();
+ // don't process the same (manifest) node more than once
+ if (inode == manifestInode) {
+ continue;
+ }
+ }
if (inode instanceof Entry) { // an updated inode
e = (Entry)inode;
try {
if (e.type == Entry.COPY) {
// entry copy: the only thing changed is the "name"
< prev index next >