]> source.dussan.org Git - poi.git/commitdiff
Bug 63029: revert handling NotOfficeXmlFileException in ZipPackage as this change...
authorYegor Kozlov <yegor@apache.org>
Wed, 13 Feb 2019 06:45:14 +0000 (06:45 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 13 Feb 2019 06:45:14 +0000 (06:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1853474 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java

index 8867e34ae77238372feb54b4b9dd2b146a98c486..9212ed5910701bec2ade7dfff78871bf285f6849 100644 (file)
@@ -144,7 +144,9 @@ public final class ZipPackage extends OPCPackage {
             if (access == PackageAccess.WRITE) {
                 throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e);
             }
-            if ("archive is not a ZIP archive".equals(e.getMessage())) {
+            // YK: this is incorrect and the exception below is never thrown.
+            // The could below should catch "archive is not a ZIP archive"
+            if ("java.util.zip.ZipException: archive is not a ZIP archive".equals(e.getMessage())) {
                 throw new NotOfficeXmlFileException("archive is not a ZIP archive", e);
             }
             LOG.log(POILogger.ERROR, "Error in zip file "+file+" - falling back to stream processing (i.e. ignoring zip central directory)");
index 4f4e4e5b5e4c6ca135348b6ab45422bf3df9e678..4caf68988ff61cfecf51bace2d6011ef7491a0ac 100644 (file)
@@ -1195,11 +1195,14 @@ public final class TestPackage {
                File tmpFile = OpenXML4JTestDataSamples.getOutputFile("Bug63029.docx");
                Files.copy(testFile, tmpFile);
 
+               int numPartsBefore = 0;
                String md5Before = Files.hash(tmpFile, Hashing.md5()).toString();
 
                RuntimeException ex = null;
                try(OPCPackage pkg = OPCPackage.open(tmpFile, PackageAccess.READ_WRITE))
                {
+                       numPartsBefore = pkg.getParts().size();
+
                        // add a marshaller that will throw an exception on save
                        pkg.addMarshaller("poi/junit", (part, out) -> {
                                throw new RuntimeException("Bugzilla 63029");
@@ -1216,10 +1219,12 @@ public final class TestPackage {
                assertEquals(md5Before, md5After);
 
                // try to read the source file once again
-               try ( OPCPackage zip = OPCPackage.open(tmpFile, PackageAccess.READ_WRITE)){
+               try ( OPCPackage pkg = OPCPackage.open(tmpFile, PackageAccess.READ_WRITE)){
                        // the source is still a valid zip archive.
                        // prior to the fix this used to throw NotOfficeXmlFileException("archive is not a ZIP archive")
 
+                       // assert that the number of parts remained the same
+                       assertEquals(pkg.getParts().size(), numPartsBefore);
                }
 
        }