after update Apache POI 4.0 - Property 'http:/

2019-06-05 10:26发布

问题:

After updating Apache POI from 3.17 to 4.0.0 i'm getting on line:

OPCPackage pck = OPCPackage.open(this.getTemplate());

an exception:

java.lang.IllegalArgumentException: Property 'http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit' is not recognized.
     at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(DocumentBuilderFactoryImpl.java:144)
     at __redirected.__DocumentBuilderFactory.setAttribute(__DocumentBuilderFactory.java:125)
     at org.apache.poi.ooxml.util.DocumentHelper.trySetXercesSecurityManager(DocumentHelper.java:143)
     at org.apache.poi.ooxml.util.DocumentHelper.<clinit>(DocumentHelper.java:108)
     at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:392)
     at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.<init>(ContentTypeManager.java:104)
     at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.<init>(ZipContentTypeManager.java:54)
     at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:258)
     at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:725)
     at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:275)
     at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:181)

They say in How to disable accessExternalDTD and entityExpansionLimit warnings with logback that i should exclude xerces, but i had this already:

  <dependency>
     <groupId>org.apache.poi</groupId>
     <artifactId>poi</artifactId>
     <version>4.0.0</version>
  </dependency>
  <dependency>
     <groupId>org.apache.poi</groupId>
     <artifactId>poi-ooxml</artifactId>
     <version>4.0.0</version>
     <exclusions>
        <exclusion>
           <groupId>xml-apis</groupId>
           <artifactId>xml-apis</artifactId>
        </exclusion>
        <exclusion>
           <groupId>xerces</groupId>
           <artifactId>xercesImpl</artifactId>
        </exclusion>
     </exclusions>
  </dependency>

My setup:

  • JDK 8
  • WildFly 14

Going back to 3.17 fixes the issue.

回答1:

the POI 4.0.0 code works with up to date versions of xerces - the code doesn't even get as far the trying to set the entity expansion limit because it will set the xerces security manager first and stop there - would you be able to try adding an explicit dependency on the latest version of xerces? https://mvnrepository.com/artifact/xerces/xercesImpl/2.12.0



回答2:

This has beed fixed in POI 4.0.1.

Corresponding bug: https://bz.apache.org/bugzilla/show_bug.cgi?id=62692