aboutsummaryrefslogtreecommitdiff
path: root/jar-infer/jar-infer-lib/src/main/java/com/uber/nullaway/jarinfer/BytecodeAnnotator.java
diff options
context:
space:
mode:
Diffstat (limited to 'jar-infer/jar-infer-lib/src/main/java/com/uber/nullaway/jarinfer/BytecodeAnnotator.java')
-rw-r--r--jar-infer/jar-infer-lib/src/main/java/com/uber/nullaway/jarinfer/BytecodeAnnotator.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/jar-infer/jar-infer-lib/src/main/java/com/uber/nullaway/jarinfer/BytecodeAnnotator.java b/jar-infer/jar-infer-lib/src/main/java/com/uber/nullaway/jarinfer/BytecodeAnnotator.java
index 94e128c..52498fd 100644
--- a/jar-infer/jar-infer-lib/src/main/java/com/uber/nullaway/jarinfer/BytecodeAnnotator.java
+++ b/jar-infer/jar-infer-lib/src/main/java/com/uber/nullaway/jarinfer/BytecodeAnnotator.java
@@ -212,6 +212,18 @@ public final class BytecodeAnnotator {
annotateBytecode(is, os, nonnullParams, nullableReturns, javaxNullableDesc, javaxNonnullDesc);
}
+ /**
+ * Create a zip entry with creation time of 0 to ensure that jars always have the same checksum.
+ *
+ * @param name of the zip entry.
+ * @return the zip entry.
+ */
+ private static ZipEntry createZipEntry(String name) {
+ ZipEntry entry = new ZipEntry(name);
+ entry.setTime(0);
+ return entry;
+ }
+
private static void copyAndAnnotateJarEntry(
JarEntry jarEntry,
InputStream is,
@@ -224,7 +236,7 @@ public final class BytecodeAnnotator {
throws IOException {
String entryName = jarEntry.getName();
if (entryName.endsWith(".class")) {
- jarOS.putNextEntry(new ZipEntry(jarEntry.getName()));
+ jarOS.putNextEntry(createZipEntry(jarEntry.getName()));
annotateBytecode(is, jarOS, nonnullParams, nullableReturns, nullableDesc, nonnullDesc);
} else if (entryName.equals("META-INF/MANIFEST.MF")) {
// Read full file
@@ -241,7 +253,7 @@ public final class BytecodeAnnotator {
if (!manifestText.equals(manifestMinusDigests) && !stripJarSignatures) {
throw new SignedJarException(SIGNED_JAR_ERROR_MESSAGE);
}
- jarOS.putNextEntry(new ZipEntry(jarEntry.getName()));
+ jarOS.putNextEntry(createZipEntry(jarEntry.getName()));
jarOS.write(manifestMinusDigests.getBytes(UTF_8));
} else if (entryName.startsWith("META-INF/")
&& (entryName.endsWith(".DSA")
@@ -251,7 +263,7 @@ public final class BytecodeAnnotator {
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()));
+ jarOS.putNextEntry(createZipEntry(jarEntry.getName()));
jarOS.write(IOUtils.toByteArray(is));
}
jarOS.closeEntry();
@@ -329,7 +341,7 @@ public final class BytecodeAnnotator {
while (zipIterator.hasNext()) {
ZipEntry zipEntry = zipIterator.next();
InputStream is = inputZip.getInputStream(zipEntry);
- zipOS.putNextEntry(new ZipEntry(zipEntry.getName()));
+ zipOS.putNextEntry(createZipEntry(zipEntry.getName()));
if (zipEntry.getName().equals("classes.jar")) {
JarInputStream jarIS = new JarInputStream(is);
JarEntry inputJarEntry = jarIS.getNextJarEntry();