aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lynggaard Hansen2012-07-07 11:17:05 (EDT)
committerHenrik Lynggaard Hansen2012-07-07 11:17:05 (EDT)
commit3b6ce84edca27ffb8265922822b1c471fd5872a7 (patch)
tree94a8aa76fbfae67b19882686df902bd2ca9a30ed
parentb3f23e82c67f65adc91ce3f463f3ceb272694b80 (diff)
downloadorg.eclipse.hudson.core-3b6ce84edca27ffb8265922822b1c471fd5872a7.zip
org.eclipse.hudson.core-3b6ce84edca27ffb8265922822b1c471fd5872a7.tar.gz
org.eclipse.hudson.core-3b6ce84edca27ffb8265922822b1c471fd5872a7.tar.bz2
FIX NPE when closing inputstream in exception pathrefs/changes/62/6662/1
- Whitespace and sonar fixes. - closing of InputStream in fianlly block of visit could cause NPE Change-Id: I98e95ed01ad4ee04105a992cf51158b40f41d9aa Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
-rw-r--r--hudson-core/src/main/java/hudson/util/io/ZipArchiver.java15
1 files changed, 9 insertions, 6 deletions
diff --git a/hudson-core/src/main/java/hudson/util/io/ZipArchiver.java b/hudson-core/src/main/java/hudson/util/io/ZipArchiver.java
index e0fc317..38d7502 100644
--- a/hudson-core/src/main/java/hudson/util/io/ZipArchiver.java
+++ b/hudson-core/src/main/java/hudson/util/io/ZipArchiver.java
@@ -16,7 +16,7 @@
package hudson.util.io;
-import hudson.util.FileVisitor;
+import hudson.util.IOUtils;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
@@ -31,6 +31,10 @@ import java.io.OutputStream;
* @see ArchiverFactory#ZIP
*/
final class ZipArchiver extends Archiver {
+
+ // Bitmask indicating directories in 'external attributes' of a ZIP archive entry.
+ private static final long BITMASK_IS_DIRECTORY = 1 << 4;
+
private final byte[] buf = new byte[8192];
private final ZipOutputStream zip;
@@ -39,6 +43,7 @@ final class ZipArchiver extends Archiver {
zip.setEncoding(System.getProperty("file.encoding"));
}
+ @Override
public void visit(File f, String relativePath) throws IOException {
if (f.isDirectory()) {
ZipEntry dirZipEntry = new ZipEntry(relativePath + '/');
@@ -52,21 +57,19 @@ final class ZipArchiver extends Archiver {
try {
in = new FileInputStream(f);
int len;
- while((len = in.read(buf)) > 0) {
+ while ((len = in.read(buf)) > 0) {
zip.write(buf, 0, len);
}
} finally {
- in.close();
+ IOUtils.closeQuietly(in);
}
zip.closeEntry();
}
entriesWritten++;
}
+ @Override
public void close() throws IOException {
zip.close();
}
-
- // Bitmask indicating directories in 'external attributes' of a ZIP archive entry.
- private static final long BITMASK_IS_DIRECTORY = 1<<4;
}