[prev in list] [next in list] [prev in thread] [next in thread] 

List:       poi-dev
Subject:    [Bug 65854] New: OPCPackage should revert() instead of close() on failed open in some cases
From:       bugzilla () apache ! org
Date:       2022-01-27 18:03:08
Message-ID: bug-65854-47293 () https ! bz ! apache ! org/bugzilla/
[Download RAW message or body]

https://bz.apache.org/bugzilla/show_bug.cgi?id=65854

            Bug ID: 65854
           Summary: OPCPackage should revert() instead of close() on
                    failed open in some cases
           Product: POI
           Version: 5.2.0-FINAL
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: trivial
          Priority: P2
         Component: OPC
          Assignee: dev@poi.apache.org
          Reporter: tallison@apache.org
  Target Milestone: ---

Thanks to PJ and Andi and the POI team, we've integrated 5.2.0 into Apache
Tika, and we're about to make a release of 2.3.0.

I noticed a bunch of logged warnings: "The close() method is intended to SAVE a
package. This package is open in READ ONLY mode, use the revert() method
instead!"

We've wrapped our use of OPCPackage so that we're calling revert() everywhere.  

However, in our zip detector, when trying to figure out if a zip is an
OPCPackage, we call OPCPackage.open(ZipEntrySource zipEntry), and if there's an
exception, we swallow it and figure that zip file is not an OPCPackage.

The problem is that at the POI level, IOUtils.closeQuietly() is called on the
pack after it is created in the catch block. 


Is there a cleaner way with POI to determine if a zip file is an OPCPackage?


Should we be calling revert() instead at the POI level to avoid this warning?

Code:

    public static OPCPackage open(ZipEntrySource zipEntry) throws
InvalidFormatException {
        ZipPackage pack = new ZipPackage(zipEntry, PackageAccess.READ);

        try {
            if (pack.partList == null) {
                pack.getParts();
            }

            return pack;
        } catch (RuntimeException | InvalidFormatException var3) {
            IOUtils.closeQuietly(pack);
            throw var3;
        }
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic