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

            Bug ID: 60128
           Summary: File left open in ZipPackage when
                    InvalidFormatException are raised
           Product: POI
           Version: 3.15-dev
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P2
         Component: OPC
          Assignee: [email protected]
          Reporter: [email protected]

Created attachment 34243
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=34243&action=edit
A invalid format file

ZipPackage isn't closing opened files  when InvalidFormatExceptions are raised. 

Running the code bellow, using the provided sample file, shows the problem,
while the sample code is running the file is open in operation system (you have
to use some SO tool to verify this).
Some details:
* To run you have to correct the path to provided file.
* The provided file is a invalid XLSX file, was created just to generate the
problem.

The Exception trace 

    at
org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:238)
    at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:726)
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:228)
    at Main.main(Main.java:14)

It's happen because ZipPackage opens the file but don't close it when a
Exception is raised.



The sample code:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;

public class Main {

    public static void main(String[] args) throws IOException {
        OPCPackage pkg = null;
        try {
            pkg = OPCPackage.open("C:/Temp/invalid file.xlsx",
PackageAccess.READ);
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (pkg != null) {
                pkg.close();
            }
        }

        BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
        String s;
        while ((s = in.readLine()) != null && s.length() != 0) {
            // Enter to end sample
        }
    }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.

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

Reply via email to