From a234740a3b00672fd66026c22ca02ccde7acbecb Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 5 Oct 2011 21:29:32 +0000 Subject: [PATCH] Fix bug #51949 - Avoid NPE on double close of ZipFileZipEntrySource git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1179452 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../openxml4j/util/ZipFileZipEntrySource.java | 36 ++++++++++--------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index b391783ff2..45c8949603 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51949 - Avoid NPE on double close of ZipFileZipEntrySource 51950 - XWPF fix for footnotes not always being present in a document 51963 - Correct AreaReference handling of references containing a sheet name which includes a comma 51955 - XSSFReader supplied StylesTables need to have the theme data available diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java index 1a0d36695d..5c2b7b35e4 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java @@ -28,21 +28,23 @@ import java.util.zip.ZipFile; * normal ZipFile implementation is. */ public class ZipFileZipEntrySource implements ZipEntrySource { - private ZipFile zipArchive; - public ZipFileZipEntrySource(ZipFile zipFile) { - this.zipArchive = zipFile; - } - - public void close() throws IOException { - zipArchive.close(); - zipArchive = null; - } - - public Enumeration getEntries() { - return zipArchive.entries(); - } - - public InputStream getInputStream(ZipEntry entry) throws IOException { - return zipArchive.getInputStream(entry); - } + private ZipFile zipArchive; + public ZipFileZipEntrySource(ZipFile zipFile) { + this.zipArchive = zipFile; + } + + public void close() throws IOException { + if(zipArchive != null) { + zipArchive.close(); + } + zipArchive = null; + } + + public Enumeration getEntries() { + return zipArchive.entries(); + } + + public InputStream getInputStream(ZipEntry entry) throws IOException { + return zipArchive.getInputStream(entry); + } } -- 2.39.5