Home » excel » excel – Getting java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.ooxml.util.DocumentHelper after upgrading to POI 4.0.0

excel – Getting java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.ooxml.util.DocumentHelper after upgrading to POI 4.0.0

Posted by: admin May 14, 2020 Leave a comment

Questions:

15 to poi 4.0.0. Here are the poi dependencies I have on classpath.

poi-4.0.0
poi-scratchpad-4.0.0
poi-ooxml-4.0.0
poi-ooxml-schemas-4.0.0
xmlbeans-3.0.1

Getting below exception when I try to close workbook

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.ooxml.util.DocumentHelper
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.save(ContentTypeManager.java:428)
at org.apache.poi.openxml4j.opc.ZipPackage.saveImpl(ZipPackage.java:518)
at org.apache.poi.openxml4j.opc.OPCPackage.save(OPCPackage.java:1493)
at org.apache.poi.openxml4j.opc.OPCPackage.close(OPCPackage.java:453)
at org.apache.poi.ooxml.POIXMLDocument.close(POIXMLDocument.java:204)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.close(XSSFWorkbook.java:590)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.close(SXSSFWorkbook.java:912)
at com.seqnc.fe.excel.ExcelConversionServiceImpl.generateStream(ExcelConversionServiceImpl.java:235)
at com.seqnc.fe.excel.ExcelConversionServiceImpl.generateStream(ExcelConversionServiceImpl.java:124)
at com.seqnc.ui.executors.graph.EvaluateGraphExecutor.executeCompanyDivisionOperation(EvaluateGraphExecutor.java:188)
at com.seqnc.ui.executors.DefaultExecutor.execute(DefaultExecutor.java:299)
at com.seqnc.ui.controller.SeqncController.executeRequest(SeqncController.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:207)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
... 47 more

Any idea what is going on?

[Update] Attaching mvn tree output for the project

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ seqnc-external ---
[INFO] com.seqnc.common:seqnc-external:jar:1.0.0
[INFO] +- com.vaadin:vaadin-compatibility-server:jar:8.0.0:compile
[INFO] |  +- com.vaadin:vaadin-server:jar:8.0.0:compile
[INFO] |  |  +- com.vaadin:vaadin-sass-compiler:jar:0.9.13:compile
[INFO] |  |  |  +- org.w3c.css:sac:jar:1.3:compile
[INFO] |  |  |  \- com.vaadin.external.flute:flute:jar:1.3.0.gg2:compile
[INFO] |  |  +- com.vaadin:vaadin-shared:jar:8.0.0:compile
[INFO] |  |  +- org.jsoup:jsoup:jar:1.8.3:compile
[INFO] |  |  \- com.googlecode.gentyref:gentyref:jar:1.2.0:compile
[INFO] |  \- com.vaadin:vaadin-compatibility-shared:jar:8.0.0:compile
[INFO] +- com.vaadin:vaadin-push:jar:8.0.0:compile
[INFO] |  \- com.vaadin.external.atmosphere:atmosphere-runtime:jar:2.4.5.vaadin1:compile
[INFO] |     \- com.vaadin.external.slf4j:vaadin-slf4j-jdk14:jar:1.6.1:compile
[INFO] +- com.vaadin:vaadin-compatibility-themes:jar:8.0.0:compile
[INFO] +- com.vaadin:vaadin-spring:jar:2.0.1:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] +- com.vaadin:vaadin-spreadsheet:jar:2.0.1:compile
[INFO] |  +- com.vaadin:vaadin-client:jar:8.0.0:compile
[INFO] |  |  +- com.google.gwt:gwt-elemental:jar:2.8.0:compile
[INFO] |  |  |  \- com.google.gwt:gwt-user:jar:2.8.0:compile
[INFO] |  |  |     +- com.google.jsinterop:jsinterop-annotations:jar:1.0.1:compile
[INFO] |  |  |     +- com.google.jsinterop:jsinterop-annotations:jar:sources:1.0.1:compile
[INFO] |  |  |     +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] |  |  |     \- javax.validation:validation-api:jar:sources:1.0.0.GA:compile
[INFO] |  |  \- org.mockito:mockito-core:jar:1.9.5:compile
[INFO] |  |     \- org.objenesis:objenesis:jar:1.0:compile
[INFO] |  +- com.vaadin:vaadin-themes:jar:8.0.0:compile
[INFO] |  \- com.vaadin:vaadin-client-compiled:jar:8.0.0:compile
[INFO] +- com.vaadin:vaadin-charts-compatibility:jar:4.0.5:compile
[INFO] |  \- com.vaadin:vaadin-charts:jar:4.0.5:compile
[INFO] |     \- com.vaadin:vaadin-charts-model:jar:4.0.5:compile
[INFO] +- net.sf.jgrapht:jgrapht:jar:0.8.3:compile
[INFO] +- org.springframework:spring-beans:jar:5.1.0.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:5.1.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:5.1.0.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:5.1.0.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:5.1.0.RELEASE:compile
[INFO] |  \- org.springframework:spring-jcl:jar:5.1.0.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:5.1.0.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:5.1.0.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:5.1.0.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-mongodb:jar:2.1.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-tx:jar:5.1.0.RELEASE:compile
[INFO] |  \- org.springframework.data:spring-data-commons:jar:2.1.0.RELEASE:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:3.8.2:compile
[INFO] +- org.springframework.data:spring-data-neo4j-aspects:jar:3.4.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-aspects:jar:4.1.9.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.7:compile
[INFO] |  +- org.aspectj:aspectjrt:jar:1.8.9:compile
[INFO] |  +- org.neo4j:neo4j-cypher-dsl:jar:2.0.1:compile
[INFO] |  +- org.neo4j:neo4j:jar:2.2.5:compile
[INFO] |  |  +- org.neo4j:neo4j-kernel:jar:2.2.5:compile
[INFO] |  |  |  +- org.neo4j:neo4j-primitive-collections:jar:2.2.5:compile
[INFO] |  |  |  +- org.neo4j:neo4j-io:jar:2.2.5:compile
[INFO] |  |  |  \- org.neo4j:neo4j-csv:jar:2.2.5:compile
[INFO] |  |  +- org.neo4j:neo4j-lucene-index:jar:2.2.5:compile
[INFO] |  |  |  \- org.apache.lucene:lucene-core:jar:3.6.2:compile
[INFO] |  |  +- org.neo4j:neo4j-graph-algo:jar:2.2.5:compile
[INFO] |  |  +- org.neo4j:neo4j-udc:jar:2.2.5:compile
[INFO] |  |  +- org.neo4j:neo4j-graph-matching:jar:2.2.5:compile
[INFO] |  |  +- org.neo4j:neo4j-cypher:jar:2.2.5:compile
[INFO] |  |  |  +- org.scala-lang:scala-library:jar:2.10.5:compile
[INFO] |  |  |  +- org.scala-lang:scala-reflect:jar:2.10.5:compile
[INFO] |  |  |  +- org.neo4j:neo4j-cypher-compiler-1.9:jar:2.0.4:compile
[INFO] |  |  |  +- org.neo4j:neo4j-cypher-compiler-2.0:jar:2.0.4:compile
[INFO] |  |  |  +- org.neo4j:neo4j-cypher-compiler-2.1:jar:2.1.8:compile
[INFO] |  |  |  +- org.neo4j:neo4j-cypher-compiler-2.2:jar:2.2.5:compile
[INFO] |  |  |  +- org.parboiled:parboiled-scala_2.10:jar:1.1.7:compile
[INFO] |  |  |  |  \- org.parboiled:parboiled-core:jar:1.1.7:compile
[INFO] |  |  |  +- net.sf.opencsv:opencsv:jar:2.3:compile
[INFO] |  |  |  \- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.4:compile
[INFO] |  |  +- org.neo4j:neo4j-jmx:jar:2.2.5:compile
[INFO] |  |  \- org.neo4j:neo4j-consistency-check:jar:2.2.5:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- commons-io:commons-io:jar:2.4:compile
[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.7.21:runtime
[INFO] +- org.springframework.data:spring-data-neo4j:jar:4.1.7.RELEASE:compile
[INFO] |  +- org.neo4j:neo4j-ogm-core:jar:2.0.6:compile
[INFO] |  |  +- org.neo4j:neo4j-ogm-api:jar:2.0.6:compile
[INFO] |  |  +- org.neo4j:neo4j-ogm-compiler:jar:2.0.6:compile
[INFO] |  |  \- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] |  \- org.neo4j:neo4j-ogm-http-driver:jar:2.0.6:compile
[INFO] +- org.springframework.data:spring-data-neo4j-rest:jar:3.4.6.RELEASE:compile
[INFO] |  +- org.neo4j.test:neo4j-harness:jar:2.2.5:compile
[INFO] |  |  +- org.neo4j.app:neo4j-server:jar:2.2.5:compile
[INFO] |  |  |  +- org.neo4j:neo4j:pom:2.2.5:compile
[INFO] |  |  |  +- org.neo4j:server-api:jar:2.2.5:compile
[INFO] |  |  |  |  \- org.neo4j.3rdparty.javax.ws.rs:jsr311-api:jar:1.1.2.r612:compile
[INFO] |  |  |  +- org.neo4j.app:neo4j-browser:jar:2.2.5:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.2:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.2:compile
[INFO] |  |  |  +- ch.qos.logback:logback-access:jar:1.1.2:compile
[INFO] |  |  |  +- org.codehaus.janino:janino:jar:2.6.1:compile
[INFO] |  |  |  |  \- org.codehaus.janino:commons-compiler:jar:2.6.1:compile
[INFO] |  |  |  +- org.eclipse.jetty:jetty-server:jar:9.2.4.v20141103:compile
[INFO] |  |  |  |  +- org.eclipse.jetty:jetty-http:jar:9.2.4.v20141103:compile
[INFO] |  |  |  |  |  \- org.eclipse.jetty:jetty-util:jar:9.2.4.v20141103:compile
[INFO] |  |  |  |  \- org.eclipse.jetty:jetty-io:jar:9.2.4.v20141103:compile
[INFO] |  |  |  +- org.eclipse.jetty:jetty-webapp:jar:9.2.4.v20141103:compile
[INFO] |  |  |  |  +- org.eclipse.jetty:jetty-xml:jar:9.2.4.v20141103:compile
[INFO] |  |  |  |  \- org.eclipse.jetty:jetty-servlet:jar:9.2.4.v20141103:compile
[INFO] |  |  |  |     \- org.eclipse.jetty:jetty-security:jar:9.2.4.v20141103:compile
[INFO] |  |  |  +- com.sun.jersey:jersey-server:jar:1.19:compile
[INFO] |  |  |  +- com.sun.jersey:jersey-servlet:jar:1.19:compile
[INFO] |  |  |  +- org.rrd4j:rrd4j:jar:2.2:compile
[INFO] |  |  |  +- org.mozilla:rhino:jar:1.7R4:compile
[INFO] |  |  |  +- bouncycastle:bcprov-jdk16:jar:140:compile
[INFO] |  |  |  +- com.sun.jersey.contribs:jersey-multipart:jar:1.19:compile
[INFO] |  |  |  |  \- org.jvnet.mimepull:mimepull:jar:1.9.3:compile
[INFO] |  |  |  \- org.neo4j:neo4j-shell:jar:2.2.5:compile
[INFO] |  |  |     \- org.apache.servicemix.bundles:org.apache.servicemix.bundles.jline:jar:0.9.94_1:compile
[INFO] |  |  +- org.neo4j:neo4j-kernel:test-jar:tests:2.2.5:compile
[INFO] |  |  +- org.neo4j:neo4j-io:test-jar:tests:2.2.5:compile
[INFO] |  |  |  \- org.neo4j:neo4j-unsafe:jar:2.2.5:compile
[INFO] |  |  \- commons-digester:commons-digester:jar:2.1:compile
[INFO] |  |     \- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.7:compile
[INFO] |  |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.7:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.7:compile
[INFO] |  \- com.sun.jersey:jersey-client:jar:1.9:compile
[INFO] |     \- com.sun.jersey:jersey-core:jar:1.9:compile
[INFO] +- org.neo4j:neo4j-enterprise:jar:3.0.7:compile
[INFO] |  +- org.neo4j:neo4j-query-logging:jar:3.0.7:compile
[INFO] |  +- org.neo4j:neo4j-com:jar:3.0.7:compile
[INFO] |  |  \- org.neo4j:neo4j-enterprise-kernel:jar:3.0.7:compile
[INFO] |  +- org.neo4j:neo4j-backup:jar:3.0.7:compile
[INFO] |  |  \- org.neo4j:neo4j-cluster:jar:3.0.7:compile
[INFO] |  +- org.neo4j:neo4j-ha:jar:3.0.7:compile
[INFO] |  +- org.neo4j:neo4j-metrics:jar:3.0.7:compile
[INFO] |  |  +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile
[INFO] |  |  \- io.dropwizard.metrics:metrics-graphite:jar:3.1.2:compile
[INFO] |  \- org.neo4j:neo4j-management:jar:3.0.7:compile
[INFO] +- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.9.7:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.7:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.7:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.9.7:compile
[INFO] |  +- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] |  \- com.fasterxml.woodstox:woodstox-core:jar:5.0.3:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.6:compile
[INFO] +- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.9.7:compile
[INFO] +- org.apache.poi:poi:jar:4.0.0:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- org.apache.poi:poi-ooxml:jar:4.0.0:compile
[INFO] |  +- org.apache.commons:commons-compress:jar:1.18:compile
[INFO] |  \- com.github.virtuald:curvesapi:jar:1.04:compile
[INFO] +- org.apache.poi:poi-ooxml-schemas:jar:4.0.0:compile
[INFO] |  \- org.apache.xmlbeans:xmlbeans:jar:3.0.1:compile
[INFO] +- org.apache.poi:poi-scratchpad:jar:4.0.0:compile
[INFO] +- net.sf.trove4j:trove4j:jar:3.0.3:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:4.0.1:provided
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.11.1:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.11.1:compile
[INFO] +- javax.mail:mail:jar:1.4.7:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- com.itextpdf:itextpdf:jar:5.5.10:compile
[INFO] +- com.google.code.gson:gson:jar:2.8.0:compile
[INFO] +- com.ning.billing:recurly-java-library:jar:0.11.0:compile
[INFO] |  +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.9.7:compile
[INFO] |  \- joda-time:joda-time:jar:2.7:compile
[INFO] +- com.chargebee:chargebee-java:jar:2.4.9:compile
[INFO] |  \- org.json:json:jar:20090211:compile
[INFO] +- com.google.guava:guava:jar:18.0:compile
[INFO] +- com.google.code.findbugs:jsr305:jar:2.0.3:compile
[INFO] +- com.ning:async-http-client:jar:1.9.40:compile
[INFO] |  \- io.netty:netty:jar:3.10.6.Final:compile
[INFO] +- quartz:quartz:jar:1.5.2:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] +- org.springframework:spring-support:jar:2.0.8:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- com.intuit.quickbooks-online:ipp-v3-java-data:jar:4.0.8:compile
[INFO] |  +- org.jvnet.jaxb2_commons:jaxb2-commons-lang:jar:2.4:compile
[INFO] |  +- org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:1.11.1:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.3:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.6:compile
[INFO] |  +- oauth.signpost:signpost-core:jar:1.2.1.1:compile
[INFO] |  +- oauth.signpost:signpost-commonshttp4:jar:1.2:compile
[INFO] |  +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
[INFO] |  +- cglib:cglib:jar:3.2.8:test
[INFO] |  |  +- org.ow2.asm:asm:jar:6.2.1:test
[INFO] |  |  \- org.apache.ant:ant:jar:1.10.3:test
[INFO] |  |     \- org.apache.ant:ant-launcher:jar:1.10.3:test
[INFO] |  +- asm:asm-commons:jar:3.3.1:compile
[INFO] |  |  \- asm:asm-tree:jar:3.3.1:compile
[INFO] |  |     \- asm:asm:jar:3.3.1:compile
[INFO] |  +- net.sf.kxml:kxml2:jar:2.2.2:compile
[INFO] |  |  \- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] |  +- com.sun.mail:javax.mail:jar:1.6.1:compile
[INFO] |  +- javax.xml.bind:jaxb-api:jar:2.2.12:compile
[INFO] |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.11:compile
[INFO] |  +- com.sun.xml.bind:jaxb-core:jar:2.2.11:compile
[INFO] |  \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.9.7:compile
[INFO] |     \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.9.7:compile
[INFO] +- com.intuit.quickbooks-online:ipp-v3-java-devkit:jar:4.0.8:compile
[INFO] \- com.intuit.quickbooks-online:oauth2-platform-api:jar:4.0.8:compile
[INFO]    \- commons-lang:commons-lang:jar:2.6:compile

As you can see I am using all latest versions of POI.

How to&Answers:

I was able to solve the problem by adding a direct dependency to xerces-impl.

 <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.12.0</version> </dependency> 

pj-fanning gave the right tip directing to https://bz.apache.org/bugzilla/show_bug.cgi?id=62692 (see comment above). I had the same problem running an application on Wildfly 13 which ships with xerces 2.11.0 dated February 2013 whereby 2.12.0 is from June 2018 (see maven repository)

Answer:

I am having the same issue. I noticed something in the change log that seems to indicate a breaking change in regards to the write() method and automatically closing the OutputStream. I am wondering if that is the issue.

https://poi.apache.org/changes.html#4.0.0

Answer:

I had the same issue and after attempting several “fixes” that didn’t work I have

added the following line to standalone.bat

 -jaxpmodule "javax.xml.jaxp-provider" ^ 

directly below the -mp “%JBOSS_MODULEPATH%” ^ line