Author: yegor
Date: Wed Feb 13 06:45:14 2019
New Revision: 1853474

URL: http://svn.apache.org/viewvc?rev=1853474&view=rev
Log:
Bug 63029: revert handling NotOfficeXmlFileException in ZipPackage as this 
change broke the build 

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

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1853474&r1=1853473&r2=1853474&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Wed 
Feb 13 06:45:14 2019
@@ -144,7 +144,9 @@ public final class ZipPackage extends OP
             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)");

Modified: 
poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java?rev=1853474&r1=1853473&r2=1853474&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java 
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java 
Wed Feb 13 06:45:14 2019
@@ -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);
                }
 
        }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to