Issue with Xerces and OSGI Classpath during Plugin Upgrade

Hi,

We are currently trying to upgrade to 7.3.6 and have a custom plugin that was incompatible that needs upgrading to be compatible. We use mybatis 3.4.4 as the ORM which has a dependency on XercesImpl and xml-apis… version 2.9.1 and 1.3.04 respectfully.

However, JIRA already has those packages in it’s externals.

When I try to use xerces (w/ xml-apis attached) directly in compile OR if I specify the system external to import their bundle I get:

Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘subversionManager’ defined in URL [bundle://248.0:0/META-INF/spring/subversion-context.xml]: Invocation of init method failed; nested exception is com.atlassian.cache.CacheException: java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory

When I try to leverage the compile only (but with ! on the org.apache.xerces*, org.apache.xpath* and javax.xml.xpath* dependencies I get a linkage error and/or NoClassDefFound for javax.xml.xpath.XPathFactory


A LinkageError indicates that plugin code was compiled with outdated versions. Unable to run plugin code because of ‘java.lang.NoClassDefFoundError - javax/xml/xpath/XPathFactory’.

Has this been seen before? I’m extremely confused how I get the OSGI Classloader to either use entirely the system and not mine. Or use mine and not the systems at all and not mismatch in the casting of versions.

I’ve attached two poms. One pom is from a working state on my local using the SDK. You will notice that it does not explicitly state the import bundles and this WORKS locally but not on the test server we have that has other plugins installed (Data is otherwise same).

The other pom is a WIP pom that i’ve been trying my darndest to get the import bundles to work and have ultimately resolved to bringing in the world and still not succeeding. The state of this one is it results in the ClassCastException above when accessing the pages.

Any help you have in solving this issue quickly is greatly appreciated!!!

Pom Working


<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company.jira.plugin</groupId>
    <artifactIdjira-plugin</artifactId>
    <version>3.0</version>
    <name>jira-plugin</name>
    <description>This is the com.company.jira.plugin:co-core plugin for Atlassian JIRA.</description>
    <packaging>atlassian-plugin</packaging>
    <dependencies>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.6</version>
            <!-- <scope>test</scope> -->
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-func-tests</artifactId>
            <version>${jira.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.ostermiller</groupId>
            <artifactId>utils</artifactId>
            <version>1.07.00</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira.plugin.ext.subversion</groupId>
            <artifactId>atlassian-jira-subversion-plugin</artifactId>
            <version>3.0.1</version>
            <!--scope>provided</scope -->
        </dependency>
        <dependency>
            <groupId>opensymphony</groupId>
            <artifactId>oscore</artifactId>
            <version>2.2.7</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
        </dependency>
        <!--
        <dependency>
            <groupId>xalan</groupId>
            <artifactId>xalan</artifactId>
            <version>2.7.2</version>
        </dependency>
        -->
        <!-- Add dependency on jira-core if you want access to JIRA implementation
			classes as well as the sanctioned API. -->
        <!-- This is not normally recommended, but may be required eg when migrating
			a plugin originally developed against JIRA 4.x -->
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-core</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
<!--
        <dependency>
            <groupId>xalan</groupId>
            <artifactId>xalan</artifactId>
            <version>2.7.2</version>
        </dependency>
       -->
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.11.0</version>
            <exclusions>
                <exclusion>
                <groupId>xml-apis</groupId>
                <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/config</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-jira-plugin</artifactId>
                <version>6.2.11</version>
                <extensions>true</extensions>
                <configuration>
                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.data.version}</productDataVersion>
                    <enableQuickReload>true</enableQuickReload>
                    <enableFastdev>false</enableFastdev>
                    <systemProperties>
                        <property>
                            <name>atlassian.org.osgi.framework.bootdelegation</name>
                            <value>sun.*,com.sun.*</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <!-- <jira.version>4.1.1.1</jira.version> <jira.data.version>4.1.1</jira.data.version>
			<jira.version>5.2.11</jira.version> -->
        <jira.version>7.3.6</jira.version>
        <jira.data.version>7.3.6</jira.data.version>
        <amps.version>6.2.14</amps.version>
    </properties>
</project>

WIP Pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company.jira.plugin</groupId>
    <artifactId>co-jira-plugin</artifactId>
    <version>3.0</version>
    <name>co-jira-plugin</name>
    <description>This is the com.company.jira.plugin:co-core plugin for Atlassian JIRA.</description>
    <packaging>atlassian-plugin</packaging>
    <dependencies>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.6</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-func-tests</artifactId>
            <version>${jira.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.4</version>
            <scope>compile</scope>
<!--
            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>jaxen</groupId>
                    <artifactId>jaxen</artifactId>
                </exclusion>
            </exclusions>
-->
        </dependency>
        <dependency>
            <groupId>org.ostermiller</groupId>
            <artifactId>utils</artifactId>
            <version>1.07.00</version>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira.plugin.ext.subversion</groupId>
            <artifactId>atlassian-jira-subversion-plugin</artifactId>
            <version>3.0.1</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>jaxen</groupId>
                    <artifactId>jaxen</artifactId>
                </exclusion>
            </exclusions>
            <!--scope>provided</scope -->
        </dependency>
        <dependency>
            <groupId>opensymphony</groupId>
            <artifactId>oscore</artifactId>
            <version>2.2.7</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
        </dependency>

         <!-- Add dependency on jira-core if you want access to JIRA implementation
			classes as well as the sanctioned API. -->
        <!-- This is not normally recommended, but may be required eg when migrating
			a plugin originally developed against JIRA 4.x -->
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-core</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.35</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

<!--        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.9.1</version>
 &lt;!&ndash;           <exclusions>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>&ndash;&gt;
        </dependency>-->


                <dependency>
                    <groupId>xalan</groupId>
                    <artifactId>xalan</artifactId>
                    <version>2.7.2</version>
                    <scope>provided</scope>
                    <exclusions>
                        <exclusion>
                            <groupId>xml-apis</groupId>
                            <artifactId>xml-apis</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>

        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            <version>2.9.1</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/config</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-jira-plugin</artifactId>
                <version>6.2.11</version>
                <extensions>true</extensions>
                <configuration>
                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.data.version}</productDataVersion>
                    <enableQuickReload>true</enableQuickReload>
                    <enableFastdev>false</enableFastdev>
                    <instructions>
                    <Import-Package>
                      <!--

                        org.apache.lucene*;version="3.2.0",
                        org.apache.lucene.search*;version="3.2.0",
                        org.apache.lucene.document*;version="3.2.0",
                        org.apache.lucene.index*;version="3.2.0",
                        org.apache.lucene.analysis*;version="3.2.0",
                        org.apache.lucene.analysis.standard*;version="3.2.0",
                        org.slf4j*;version="1.6.4",
                        org.apache.commons.lang*;version="2.5",
                        com.atlassian.jira*;version="7.0",
                        com.atlassian.jira.extension*;version="7.0",
                        com.atlassian.jira.service*;version="7.0",
                        com.atlassian.configurable*;version="7.0",
                        com.atlassian.jira.issue.tabpanels*;version="7.0",
                        com.atlassian.jira.plugin.issuetabpanel*;version="7.0",
                        com.atlassian.jira.plugin.projectpanel*;version="7.0",
                        com.atlassian.jira.plugin.projectpanel.impl*;version="7.0",
                        com.atlassian.jira.web.action*;version="7.0",
                        com.atlassian.jira.web.action.issue*;version="7.0",
                        com.atlassian.jira.web.bean*;version="7.0",
                        com.atlassian.jira.project*;version="7.0",
                        com.atlassian.jira.project.browse*;version="7.0",
                        com.atlassian.jira.component*;version="7.0",
                        com.atlassian.core.util*;version="4.6.2",
                        com.atlassian.plugin.event.events;version="3.0.5",
                        org.apache.commons.collections.map*;version="3.2.1",
                        javax.net.ssl*;version="0.0.0",
                        javax.servlet.http*;version="0.0.0",
                        javax.xml.parsers*;version="0.0.0",
                        webwork.action*;version="1.4-atlassian-22",
                        webwork.action.factory*;version="1.4-atlassian-22",
                        com.opensymphony.util*;version="2.2.7-atlassian-1",
                        com.opensymphony.module.propertyset.*;version="0.0.0",
                        org.xml.sax*;version="0.0.0",
                        org.xml.sax.helpers*;version="0.0.0",
                        org.springframework.beans.factory*;version="2.5.6",
                        com.atlassian.sal.api.lifecycle*;version="2.0.0",
                        javax.crypto*;version="0.0.0",
                        org.apache.xerces*;version="0.0.0";resolution:=optional,
                        javax.crypto.spec*;version="0.0.0",
                        com.google.guava*;version="11.0.2-atlassian-01",
                        com.google.common.collect*;version="11.0.2-atlassian-01",
                        com.atlassian.cache.ehcache*;version="2.0.0",
                        com.opensymphony.workflow.*;version="0.0.0",
                        org.apache.log4j.*;version="0.0.0",
                        javax.xml.xpath.XPathFactory*;version="0.0.0",
                        org.apache.xpath.jaxp*;version="0.0.0"
                        -->
                        org.apache.xerces.impl.xpath;version="2.9.1"
                        org.apache.xerces.impl.xpath.*;version="2.9.1",
                        org.apache.xerces.impl.xpath*;version="2.9.1",
                        org.apache.xerces*;version="2.9.1",
                        org.apache.xalan;version="2.7.2",
                        org.apache.xalan.*;version="2.7.2",
                        org.apache.xalan*;version="2.7.2",
                        javax.xml.parsers*;resoluton:=optional,
                        org.apache.xpath*;version="0.0.0",
                        org.apache.xpath.*;version="0.0.0",
                        com.mchange.v2.c3p0;resolution:=optional,
                        *;resolution:=optional


                    </Import-Package>
                    </instructions>

                    <systemProperties>
                        <property>
                            <name>atlassian.org.osgi.framework.bootdelegation</name>
                            <value>javax.xml.xpath.*,org.apache.xerces.impl.*,org.apache.xalan*</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <jira.version>7.3.6</jira.version>
        <jira.data.version>7.3.6</jira.data.version>
        <amps.version>6.2.14</amps.version>
    </properties>
</project>

Hi, I am getting the same error with Jira, could you solve that problem?