poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 60128] New: File left open in ZipPackage when InvalidFormatException are raised
Date Tue, 13 Sep 2016 19:42:35 GMT

            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: dev@poi.apache.org
          Reporter: matafagafo@yahoo.com

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

The Exception trace 

    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",
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (pkg != null) {

        BufferedReader in = new BufferedReader(new
        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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org

View raw message