Bug 60234 - Regression: XSSFWorkBook#<init>() throws unexpected exception in 3.15 for invalid input
Summary: Regression: XSSFWorkBook#<init>() throws unexpected exception in 3.15 for inv...
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.15-FINAL
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2016-10-10 15:45 UTC by Andreas Kohn
Modified: 2016-10-11 08:18 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Kohn 2016-10-10 15:45:03 UTC
We have a piece of code that essentially does this:

try {
  new XSSFWorkbook(new ByteArrayInputStream("garbage".getBytes());
} catch (POIXMLException e) {
  // Ok, guess it wasn't OOXML, so try something else.
  // ...

This worked fine in 3.14 and before. After I updated to 3.15 it fails, because we're now seeing a 'org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException' instead:

org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException: No valid entries or contents found, this is not a valid OOXML (Office Open XML) file
	at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:290)
	at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:774)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:344)
	at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:285)
	at ...
Comment 1 Andreas Kohn 2016-10-10 15:46:24 UTC
Work-around: For now I've changed the catch to catch all RuntimeExceptions, but that's obviously not very nice.
Comment 2 Nick Burch 2016-10-10 16:48:06 UTC
NotOfficeXmlFileException extends from UnsupportedFileFormatException, which is in the core POI jar and has been around for a while. The fix to give a more helpful exception brings the OOXML code more in line with the behaviour of the other formats

I'd suggest you change your code to catch org.apache.poi.UnsupportedFileFormatException as your primary "is this a supported file" exception
Comment 3 Andreas Kohn 2016-10-11 08:18:47 UTC
Thanks a lot for confirming that this is intentional, I've adjusted my code!