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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
