Bug 64274 - ExtractorFactory#createExtractor shall throw POIXMLException
Summary: ExtractorFactory#createExtractor shall throw POIXMLException
Status: RESOLVED WONTFIX
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 4.1.x-dev
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-28 01:03 UTC by zhonghao
Modified: 2020-08-16 14:21 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description zhonghao 2020-03-28 01:03:50 UTC
When OOXML file is invalid, org.apache.poi.ooxml.extractor.ExtractorFactory#createExtractor throws IllegalArgumentException:

 public static POITextExtractor createExtractor(OPCPackage pkg) throws IOException, OpenXML4JException, XmlException {
   ...
 if (core.size() != 1) {
      throw new IllegalArgumentException("Invalid OOXML Package received - expected 1 core document, found " + core.size());
            }
 }

POI already implements POIXMLException for this type of problem. Other methods all throw this exception:

org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart#getPartFromOPCPackage

org.apache.poi.ooxml.POIXMLDocumentPart.RelationPart#getPartFromOPCPackage

org.apache.poi.xssf.eventusermodel.XSSFReader#XSSFReader

Please update the exception of createExtractor, so it is easier to catch this type of problems.
Comment 1 Andreas Beeker 2020-08-16 14:21:18 UTC
I've reworked the Extractor API for POI 5.0 and the main entry point is now in the main package (org.apache.poi.extractor.ExtractorFactory), which doesn't know about POIXMLException. It only declares a IOException and - if I don't missed something - this wraps all un-/checked exceptions.

So if the source exception is important to you, please inspect the exception cause.

POIXMLException is anyway a runtime exception - probably because of laziness - and we usually don't declare those.