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 2022/09/26 06:21:12 UTC

[Bug 66275] New: SXSSFSheet generated temporary files remains on disk

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

            Bug ID: 66275
           Summary: SXSSFSheet generated temporary files remains on disk
           Product: POI
           Version: 5.2.2-FINAL
          Hardware: PC
                OS: Mac OS X 10.1
            Status: NEW
          Severity: normal
          Priority: P2
         Component: SXSSF
          Assignee: dev@poi.apache.org
          Reporter: vahapt@gmail.com
  Target Milestone: ---

After SheetDataWriter.finalize() method is removed, SheetDataWriter.dispose()
is not called anymore. Thus _fd, the temporary file created per sheet remains
on disk.

Solution suggestion, add the code to SheetDataWriter.close() method, sample
shown below:

public void close() throws IOException 
{
    // this would break writing the same document multiple times: _out.flush();
    _out.close();
    //Moved from finalize() method
    if (!_fd.delete()) 
    {
        logger.log(POILogger.ERROR, "Can't delete temporary encryption file:
"+_fd);
    }
}

-- 
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 66275] SXSSFSheet generated temporary files remains on disk

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

vahapt@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #5 from vahapt@gmail.com ---
Got it thanks, marking the issue as invalid.

-- 
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 66275] SXSSFSheet generated temporary files remains on disk

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

--- Comment #3 from vahapt@gmail.com ---
I'm not, that should do the trick. So, I should call SXSSFWorkbook.dispose()
after SXSSFWorkbook.close()?

SXSSFWorkbook is an AutoClosable object and isn't it cleaner if close() handles
both? After Workbook is closed, we don't need any resources anyway.

-- 
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 66275] SXSSFSheet generated temporary files remains on disk

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #2 from PJ Fanning <fa...@yahoo.com> ---
SheetDataWriter.dispose() is called by SXSSFSheet.dispose() which is called by
SXSSFWorkbook.dispose(). SXSSFWorkbook.dispose() is the only one that is public
but should always be called.

So the question is are you calling SXSSFWorkbook.dispose()?

-- 
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 66275] SXSSFSheet generated temporary files remains on disk

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

--- Comment #4 from PJ Fanning <fa...@yahoo.com> ---
You need to call both close and dispose.

The Javadoc on dispose.

    /**
     * Dispose of temporary files backing this workbook on disk.
     * Calling this method will render the workbook unusable.
     * @return true if all temporary files were deleted successfully.
     */

It may be possible to change this in a future release but this is how it
currently works.

-- 
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 66275] SXSSFSheet generated temporary files remains on disk

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

--- Comment #1 from vahapt@gmail.com ---
(In reply to vahapt from comment #0)
> After SheetDataWriter.finalize() method is removed,
> SheetDataWriter.dispose() is not called anymore. Thus _fd, the temporary
> file created per sheet remains on disk.
> 
> Solution suggestion, add the code to SheetDataWriter.close() method, sample
> shown below:
> 
> public void close() throws IOException 
> {
>     // this would break writing the same document multiple times:
> _out.flush();
>     _out.close();
>     //Moved from finalize() method
>     if (!_fd.delete()) 
>     {
>         logger.log(POILogger.ERROR, "Can't delete temporary encryption file:
> "+_fd);
>     }
> }

Update:
If the patch above is applied, 
SXSSFSheet.getWorksheetXMLInputStream() calls SheetDataWriter.close() while
generating excel file and causes the temporary file to be deleted in the middle
of processing. I'm not sure why _writer.close() call is there, theoretically
inner _writer object should be closed when the sheet is closed.

/* Gets "<sheetData>" document fragment*/
public InputStream getWorksheetXMLInputStream() throws IOException {
    // flush all remaining data and close the temp file writer
    flushRows(0);
    _writer.close();
    return _writer.getWorksheetXMLInputStream();
}


----- 
If _writer.close() cannot be removed from
SXSSFSheet.getWorksheetXMLInputStream() or will have severe side effects,
secondary suggestion is to call SheetDataWriter.dispose() on
SXSSFWorkbook.close() method. Patched version is provided below:

@Override
public void close() throws IOException 
{
    // ensure that any lingering writer is closed
    for (SXSSFSheet sheet : _xFromSxHash.values())
    {
        try 
        {
            SheetDataWriter _writer = sheet.getSheetDataWriter();
            if (_writer != null)
            {
                _writer.close();
                _writer.dispose(); //VahapT: Patch to instruct deletion of
generated temporary file
            }
        } 
        catch (IOException e) 
        {
            LOG.atWarn().withThrowable(e).log("An exception occurred while
closing sheet data writer for sheet {}.", sheet.getSheetName());
        }
    }
    // Tell the base workbook to close, does nothing if
    //  it's a newly created one
    _wb.close();
}

-- 
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 66275] SXSSFSheet generated temporary files remains on disk

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

vahapt@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vahapt@gmail.com

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