in jar-infer/jar-infer-lib/src/main/java/com/uber/nullaway/jarinfer/BytecodeAnnotator.java [326:373]
public static void annotateBytecodeInAar(
ZipFile inputZip,
ZipOutputStream zipOS,
MethodParamAnnotations nonnullParams,
MethodReturnAnnotations nullableReturns,
boolean stripJarSignatures,
boolean debug)
throws IOException {
BytecodeAnnotator.debug = debug;
LOG(debug, "DEBUG", "nullableReturns: " + nullableReturns);
LOG(debug, "DEBUG", "nonnullParams: " + nonnullParams);
// Error Prone doesn't like usages of the old Java Enumerator APIs. ZipFile does not implement
// Iterable, and likely never will (see https://bugs.openjdk.java.net/browse/JDK-6581715).
// Additionally, inputZip.stream() returns a Stream<? extends ZipEntry>, and a for-each loop
// has trouble handling the corresponding ::iterator method reference. So this seems like the
// best remaining way:
Iterator<? extends ZipEntry> zipIterator = inputZip.stream().iterator();
while (zipIterator.hasNext()) {
ZipEntry zipEntry = zipIterator.next();
InputStream is = inputZip.getInputStream(zipEntry);
zipOS.putNextEntry(createZipEntry(zipEntry.getName()));
if (zipEntry.getName().equals("classes.jar")) {
JarInputStream jarIS = new JarInputStream(is);
JarEntry inputJarEntry = jarIS.getNextJarEntry();
ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
JarOutputStream jarOS = new JarOutputStream(byteArrayOS);
while (inputJarEntry != null) {
copyAndAnnotateJarEntry(
inputJarEntry,
jarIS,
jarOS,
nonnullParams,
nullableReturns,
androidNullableDesc,
androidNonnullDesc,
stripJarSignatures);
inputJarEntry = jarIS.getNextJarEntry();
}
jarOS.flush();
jarOS.close();
zipOS.write(byteArrayOS.toByteArray());
} else {
zipOS.write(IOUtils.toByteArray(is));
}
zipOS.closeEntry();
}
}