From: Nick Burch Date: Thu, 24 Apr 2014 14:50:52 +0000 (+0000) Subject: Correct an eclipse warning around close(), and a related bug that this identified X-Git-Tag: REL_3_11_BETA1~184 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=02abb3319590080a25ba0cf6c4cac15cb095586d;p=poi.git Correct an eclipse warning around close(), and a related bug that this identified git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1589756 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java index 676ccba7d0..5cc894f7de 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -403,6 +403,11 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { revert(); return; } + if (this.contentTypeManager == null) { + logger.log(POILogger.WARN, + "Unable to call close() on a package that hasn't been fully opened yet"); + return; + } // Save the content ReentrantReadWriteLock l = new ReentrantReadWriteLock(); diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java index 33fd241eda..9ac8fd17fa 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java @@ -64,6 +64,10 @@ public final class ZipPackage extends Package { public ZipPackage() { super(defaultPackageAccess); this.zipArchive = null; + + try { + this.contentTypeManager = new ZipContentTypeManager(null, this); + } catch (InvalidFormatException e) {} } /** diff --git a/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java b/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java index 56ba0e7e8d..089ed5dc5d 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java +++ b/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java @@ -73,7 +73,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor { public static void main(String[] args) throws Exception { if(args.length < 1) { System.err.println("Use:"); - System.err.println(" HXFWordExtractor "); + System.err.println(" XWPFWordExtractor "); System.exit(1); } POIXMLTextExtractor extractor = @@ -81,6 +81,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor { args[0] )); System.out.println(extractor.getText()); + extractor.close(); } public String getText() {