You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2026/09/07 11:26:26 UTC

[PR] Close file-backed resources when workbook/extractor construction fails [poi]

pjfanning opened a new pull request, #1248:
URL: https://github.com/apache/poi/pull/1248

   Three factory methods open a file-backed resource, then only clean it up for a subset of the exceptions the following call can actually throw. The remaining exception types leak the underlying file handle.
   
   ### `HSSFWorkbookFactory.create(File, String, boolean)`
   
   Catches only `RuntimeException`, but `HSSFWorkbook(POIFSFileSystem, boolean, char[])` is declared `throws IOException`. A corrupt or truncated `.xls` that fails with an `IOException` leaks the `RandomAccessFile` behind the `POIFSFileSystem`.
   
   ### `XSSFWorkbookFactory.createWorkbook(OPCPackage)`
   
   Same gap — catches only `RuntimeException` while `new XSSFWorkbook(pkg)` throws `IOException`. Reached from `create(File, String, boolean)`, the package is `ZipFile`-backed, so the zip handle leaks.
   
   ### `POIXMLExtractorFactory.create(File, String)`
   
   Handles `InvalidFormatException` and `IOException` but not `RuntimeException`. The `InputStream` overload directly below it already has that arm, and it is the `File` variant that actually holds a descriptor.
   
   ### Fix
   
   Each catch clause is widened to a multi-catch that reverts/closes and rethrows the original exception unchanged — no exception types are wrapped or swallowed, so caller-visible behaviour is unchanged apart from the resource now being released. `ExtractorFactory.createExtractor(File, String)` already uses this `catch (IOException | RuntimeException)` shape.
   
   No public signatures change, so there is nothing for MiMa to check. `:poi:compileJava` and `:poi-ooxml:compileJava` pass.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] Close file-backed resources when workbook/extractor construction fails [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #1248:
URL: https://github.com/apache/poi/pull/1248


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org