RFR: 8276400: openjdk image Jars, Zips and Jmods built from the same source are not reproducible
Michael Bien
duke at openjdk.java.net
Fri Nov 5 01:46:10 UTC 2021
On Thu, 4 Nov 2021 20:56:45 GMT, Andrew Leonard <aleonard at openjdk.org> wrote:
> This PR enables reproducible Jars, Jmods and openjdk image zip files (eg.src.zip).
> It provides support for SOURCE_DATE_EPOCH for Jar, Jmod and underlying ZipOutputStream's.
> It fixes the following keys issues relating to reproducibility:
> - Jar and ZipOutputStream are not SOURCE_DATE_EPOCH aware
> - Jar and ZipOutputStream now detect SOURCE_DATE_EPOCH environment setting
> - Jar and Jmod file content ordering was non-determinsitic
> - Fixes to Jar and Jmod main's to ensure sorted classes content ordering
> - openjdk image zip file generation used "zip" which is non-determinsitic
> - New openjdk build tool "GenerateZip" which produces the final determinsitic zip files as part of the build and also detects SOURCE_DATE_EPOCH
>
> Signed-off-by: Andrew Leonard <anleonar at redhat.com>
a few minor comments
make/jdk/src/classes/build/tools/generatezip/GenerateZip.java line 96:
> 94: ok = createOk;
> 95: }
> 96: out.close();
could be a try-with-resource block
make/jdk/src/classes/build/tools/generatezip/GenerateZip.java line 191:
> 189: Iterator<Map.Entry<String, Path>> itr = filesToProcess.entrySet().iterator();
> 190: while(itr.hasNext()) {
> 191: Map.Entry<String, Path> entry = itr.next();
could be `for (Map.Entry<String, Path> entry : filesToProcess.entrySet())`
make/jdk/src/classes/build/tools/generatezip/GenerateZip.java line 262:
> 260: zos.write(buf, 0, len);
> 261: }
> 262: is.close();
try-with-resource candidate + in.transferTo(zos)
make/jdk/src/classes/build/tools/generatezip/GenerateZip.java line 291:
> 289: newArgs.add(arg);
> 290: }
> 291: return newArgs.toArray(new String[newArgs.size()]);
something might be missing here. It just adds args to a list and makes it an array again + If the language level allows it toArray(String[]::new) could be used.
src/java.base/share/classes/java/util/zip/ZipOutputStream.java line 106:
> 104: value = -1;
> 105: }
> 106: return new Long(value);
value can be returned here directly which will use auto-boxing. (new Long(long) is deprecated).
src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java line 799:
> 797: Iterator<Map.Entry<String, Path>> itr = filesToProcess.entrySet().iterator();
> 798: while(itr.hasNext()) {
> 799: Map.Entry<String, Path> entry = itr.next();
another for-each candidate
test/jdk/java/util/zip/ZipSourceDateEpoch.java line 71:
> 69: zos.close();
> 70: os.close();
> 71: }
try-with-resource
test/jdk/java/util/zip/ZipSourceDateEpoch.java line 97:
> 95: zis.close();
> 96: fis.close();
> 97: }
try-with-resource
-------------
PR: https://git.openjdk.java.net/jdk/pull/6268
More information about the compiler-dev
mailing list