From 67d97d8894227fa2152854a03bde7254f748fc66 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 24 Apr 2014 14:50:52 +0000 Subject: [PATCH] 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 --- src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java | 5 +++++ src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java | 4 ++++ .../org/apache/poi/xwpf/extractor/XWPFWordExtractor.java | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) 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 676ccba7d..5cc894f7d 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 33fd241ed..9ac8fd17f 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 56ba0e7e8..089ed5dc5 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() {