Skip to content

Commit

Permalink
Fix jarinfer cli output determinism
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviernotteghem committed Dec 21, 2023
1 parent 10761d9 commit 30208f6
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ private static void copyAndAnnotateJarEntry(
throws IOException {
String entryName = jarEntry.getName();
if (entryName.endsWith(".class")) {
jarOS.putNextEntry(new ZipEntry(jarEntry.getName()));
ZipEntry entry = new ZipEntry(jarEntry.getName());
entry.setTime(0);
entry.setCreationTime(FileTime.fromMillis(0));
jarOS.putNextEntry(entry);
annotateBytecode(is, jarOS, nonnullParams, nullableReturns, nullableDesc, nonnullDesc);
} else if (entryName.equals("META-INF/MANIFEST.MF")) {
// Read full file
Expand All @@ -241,7 +244,10 @@ private static void copyAndAnnotateJarEntry(
if (!manifestText.equals(manifestMinusDigests) && !stripJarSignatures) {
throw new SignedJarException(SIGNED_JAR_ERROR_MESSAGE);
}
jarOS.putNextEntry(new ZipEntry(jarEntry.getName()));
ZipEntry entry = new ZipEntry(jarEntry.getName());
entry.setTime(0);
entry.setCreationTime(FileTime.fromMillis(0));
jarOS.putNextEntry(entry);
jarOS.write(manifestMinusDigests.getBytes(UTF_8));
} else if (entryName.startsWith("META-INF/")
&& (entryName.endsWith(".DSA")
Expand All @@ -251,7 +257,10 @@ private static void copyAndAnnotateJarEntry(
throw new SignedJarException(SIGNED_JAR_ERROR_MESSAGE);
} // the case where stripJarSignatures==true is handled by default by skipping these files
} else {
jarOS.putNextEntry(new ZipEntry(jarEntry.getName()));
ZipEntry entry = new ZipEntry(jarEntry.getName());
entry.setTime(0);
entry.setCreationTime(FileTime.fromMillis(0));
jarOS.putNextEntry(entry);
jarOS.write(IOUtils.toByteArray(is));
}
jarOS.closeEntry();
Expand Down Expand Up @@ -329,7 +338,10 @@ public static void annotateBytecodeInAar(
while (zipIterator.hasNext()) {
ZipEntry zipEntry = zipIterator.next();
InputStream is = inputZip.getInputStream(zipEntry);
zipOS.putNextEntry(new ZipEntry(zipEntry.getName()));
ZipEntry entry = new ZipEntry(zipEntry.getName());
entry.setTime(0);
entry.setCreationTime(FileTime.fromMillis(0));
zipOS.putNextEntry(entry);
if (zipEntry.getName().equals("classes.jar")) {
JarInputStream jarIS = new JarInputStream(is);
JarEntry inputJarEntry = jarIS.getNextJarEntry();
Expand Down

0 comments on commit 30208f6

Please sign in to comment.