You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2020/05/28 08:45:12 UTC

[Bug 64477] New: [PATCH] prevent duplicate delete of temporary file of SXSSF SheetDataWriter

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

            Bug ID: 64477
           Summary: [PATCH] prevent duplicate delete of temporary file of
                    SXSSF SheetDataWriter
           Product: POI
           Version: 4.1.2-FINAL
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: SXSSF
          Assignee: dev@poi.apache.org
          Reporter: neo.wcng@gmail.com
  Target Milestone: ---

Created attachment 37272
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=37272&action=edit
patch to prevent duplicate call to delete temporary file

TL;DR: 
if we call the SXSSFWorkbook.dispose(), the finalizer of SheetDataWriter will
attempt to delete the already deleted temporary files. The POI library will
create an error log which in fact is a false alarm.
The submitted patch is to check the existence of the file before calling the
File.delete() method.



Long version: 
According to the doc, 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note that SXSSF allocates temporary files that you must always clean up
explicitly, by calling the dispose method.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In our app, after we write the excel file using SXSSFWorkbook, we follow the
guideline to call the method SXSSFWorkbook.dispose(). 

It will then iterate the SXSSFSheet and call SXSSFSheet.dispose() which in turn
call the SheetDataWriter.dispose() method. This method will remove the
temporary file created.

    boolean dispose() throws IOException {
        final boolean ret;
        try {
            _out.close();
        } finally {
            ret = _fd.delete();
        }
        return ret;
    }


But the problem is, when the JVM GC run, it will call the
SheetDataWriter.finalize() method, which will remove the same file again.

    @Override
    protected void finalize() throws Throwable {
        if (!_fd.delete()) {
            logger.log(POILogger.ERROR, "Can't delete temporary encryption
file: "+_fd);
        }

        super.finalize();
    }

Although the app will not crash, this log is annoying and create a false alarm.

-- 
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


[Bug 64477] [PATCH] prevent duplicate delete of temporary file of SXSSF SheetDataWriter

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64477

PJ Fanning <fa...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

-- 
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


[Bug 64477] [PATCH] prevent duplicate delete of temporary file of SXSSF SheetDataWriter

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64477

--- Comment #1 from PJ Fanning <fa...@yahoo.com> ---
Comment on attachment 37272
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=37272
patch to prevent duplicate call to delete temporary file

Thanks. Merged with https://svn.apache.org/repos/asf/poi/trunk@1878227

-- 
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