Class cannot be loaded when restarting Jira Software

Hi All,

We recently encountered errors related to class initialization of apache poi dependencies despite not changing the version/dependency at all since 2017. It seems that a class cannot be loaded even during Jira Software restart. We are getting error 500 from our export capabilities due to this. This is not 100% reproducible but the only time that we did reproduce the issue locally was when we tried removing dom4j.jar from this directory: \Atlassian\Jira.install4j\user. Below are some of our stack traces.

java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller
java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161) [?:?]
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141) [?:?]
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:97) [?:?]
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324) [?:?]
java.lang.ExceptionInInitializerError
	at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161) [?:?]
	at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141) [?:?]
	at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:97) [?:?]
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:324) [?:?]
Caused by: java.lang.ClassCastException: org.apache.xerces.stax.XMLEventFactoryImpl cannot be cast to javax.xml.stream.XMLEventFactory
	at javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30) [?:1.8.0_275]
	at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41) [?:?]

There are similar errors like these in other communities and below are some solutions that we have tried. These worked for others but not for our servers that encounter the issue.

  1. Manipulating pom.xml (Jira software is restarted every after pom changes)
    Added exclusions for stax-api, xml-apis and dom4j under poi-ooxml and poi-ooxml-schemas. Also added optional tags.
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi-ooxml</artifactId>
	<version>3.16</version>
	<scope>compile</scope>
	<optional>true</optional>
	<exclusions>
		<exclusion>
			<groupId>stax</groupId>
			<artifactId>stax-api</artifactId>
		</exclusion>
		<exclusion>
			<groupId>xml-apis</groupId>
			<artifactId>xml-apis</artifactId>
		</exclusion>
		<exclusion>
			<groupId>dom4j</groupId>
			<artifactId>dom4j</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi-ooxml-schemas</artifactId>
	<version>3.16</version>
	<scope>compile</scope>
	<optional>true</optional>
	<exclusions>
		<exclusion>
			<groupId>stax</groupId>
			<artifactId>stax-api</artifactId>
		</exclusion>
		<exclusion>
			<groupId>xml-apis</groupId>
			<artifactId>xml-apis</artifactId>
		</exclusion>
		<exclusion>
			<groupId>dom4j</groupId>
			<artifactId>dom4j</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>ooxml-schemas</artifactId>
	<version>1.3</version>
	<optional>true</optional>
</dependency>

We have also removed the exclusions and optional tags in one case to test if the exclusions were causing the issue but this also did not work.

  1. Clearing plugin cache
    Moved the .install4j folder but it did not resolve the problem.

In one of our environments, this problem only occurs in one node but not in the rest of the nodes (1 out of 4) although we expect plugins to be loaded in a similar manner when each node is restarted.

Any ideas on the matter? Thank you!

1 Like

With these configuration I ran Apache POI successful about 9 years.

       <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.9</version>
            <scope>compile</scope>
        </dependency>
		<dependency>
           <groupId>org.apache.poi</groupId>
           <artifactId>poi-ooxml</artifactId>
           <version>3.9</version>
		   <scope>compile</scope>
        </dependency>
		<dependency>
           <groupId>org.apache.poi</groupId>
           <artifactId>poi-ooxml-schemas</artifactId>
           <version>3.9</version>
		   <scope>compile</scope>
        </dependency>
		<dependency>
           <groupId>org.apache.xmlbeans</groupId>
           <artifactId>xmlbeans</artifactId>
           <version>2.6.0</version>
	       <scope>compile</scope>
        </dependency>

Hi @matti.kiviharju,

Thank you for your response. We have pretty much the same configuration except for the version and some exclusions. This is our original configuration that worked for us for about 4 years:

<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi-ooxml</artifactId>
	<version>3.16</version>
	<scope>compile</scope>
	<exclusions>
		<exclusion>
			<groupId>stax</groupId>
			<artifactId>stax-api</artifactId>
		</exclusion>
		<exclusion>
			<groupId>xml-apis</groupId>
			<artifactId>xml-apis</artifactId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi-ooxml-schemas</artifactId>
	<version>3.16</version>
	<scope>compile</scope>
</dependency>
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>ooxml-schemas</artifactId>
	<version>1.3</version>
	<scope>compile</scope>
</dependency>

We also tried using the exact configuration you have but with version 3.16 and it still did not work for our environments that encounter the problem.

I have that experience about Apache POI such as only latest version of that Framework works with Atlassian Confluence Server and previous versions do not work. So possible some how latest version of the Jira Server is changed that way Apache POI 3.16 do not work anymore.

Hi @matti.kiviharju,

We upgraded our apache poi version from 3.16 to 4.1.2 (without exclusions) and it worked in our environments that encountered the problem. Apparently, newer versions don’t use stax anymore and the old-xerces build issues have been fixed from version 4.0.1 upward based on apache poi’s version change: 62805

You provided a similar workaround as what someone else from the apache community suggested in our other thread, so I will mark your comment as the solution. Thank you!