diff options
3 files changed, 11 insertions, 5 deletions
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java index 1aed0f9779..4bc1f922fe 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.java @@ -122,6 +122,9 @@ public class GenClass { String className = name.substring(0, name.length() - ".class".length()); if (prefixesContains(generatedPrefixes, className)) { Files.createDirectories(tempDir.resolve(name).getParent()); + // InputStream closing: JarFile extends ZipFile, and ZipFile.close() will close all of the + // input streams previously returned by invocations of the getInputStream method. + // See https://docs.oracle.com/javase/8/docs/api/java/util/zip/ZipFile.html#close-- Files.copy(jar.getInputStream(entry), tempDir.resolve(name)); } } diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarCreator.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarCreator.java index 46232bc879..eb25a23e4d 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarCreator.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarCreator.java @@ -147,13 +147,16 @@ public class JarCreator extends JarHelper { } private byte[] manifestContent() throws IOException { - Manifest manifest; if (manifestFile != null) { - FileInputStream in = new FileInputStream(manifestFile); - manifest = new Manifest(in); + try (FileInputStream in = new FileInputStream(manifestFile)) { + return manifestContentImpl(new Manifest(in)); + } } else { - manifest = new Manifest(); + return manifestContentImpl(new Manifest()); } + } + + private byte[] manifestContentImpl(Manifest manifest) throws IOException { Attributes attributes = manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); Attributes.Name createdBy = new Attributes.Name("Created-By"); diff --git a/third_party/ijar/test/ijar_test.sh b/third_party/ijar/test/ijar_test.sh index 5279f15f84..0b9a92fb2d 100755 --- a/third_party/ijar/test/ijar_test.sh +++ b/third_party/ijar/test/ijar_test.sh @@ -41,7 +41,7 @@ shift source ${DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; } function cleanup() { - rm -fr "${TEST_TMPDIR:-sentinel}"/* + rm -fr "$TEST_TMPDIR"/* } trap cleanup EXIT |