< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java

Print this page
rev 58246 : 8240333: jmod incorrectly updates .jar and .jmod files during hashing

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -985,10 +985,18 @@
                             ze.setTime(System.currentTimeMillis());
                             jos.putNextEntry(ze);
                             recordHashes(in, jos, moduleHashes);
                             jos.closeEntry();
                         } else {
+                            // We can't know which exact Deflater and which
+                            // compression level was used to compress the entry.
+                            // Setting "compressedSize" to "-1" prevents an error
+                            // in ZipOutputStream.closeEntry() if the newly
+                            // delfated entry will have another size than the
+                            // original compressed entry. See:
+                            // ZipOutputStream.putNextEntry()/closeEntry()
+                            e.setCompressedSize(-1);
                             jos.putNextEntry(e);
                             jos.write(in.readAllBytes());
                             jos.closeEntry();
                         }
                     } catch (IOException x) {
< prev index next >