Quarkus: @QuarkusTest classloader problems when executing XPathFactory.newInstance()

Created on 7 Apr 2020  路  7Comments  路  Source: quarkusio/quarkus

Hi guys, I've faced an issue when parsing a .xlsx file in my JUnit tests.

The problem is that an internal lib tries to call the following code:

XPathFactory.newInstance()

Suppose we have the followings scenarios:

@org.junit.Test
    public void testXpathFactory() {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        assertNotNull(xPathFactory);
    }
@Test //@org.junit.jupiter.api.Test
    public void testXpathFactory() {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        assertNotNull(xPathFactory);
    }

The first one executes ok, the last one throws the error:

java.lang.RuntimeException: XPathFactory#newInstance() failed to create an XPathFactory for the default object model: http://java.sun.com/jaxp/xpath/dom with the XPathFactoryConfigurationException: javax.xml.xpath.XPathFactoryConfigurationException: No XPathFctory implementation found for the object model: http://java.sun.com/jaxp/xpath/dom

Both scenarios are in a class annotated with the @QuarkusTest

Any ideas on how I can solve this?

Best.

aretesting kinbug

All 7 comments

I wasn't able to reproduce this in a simple test.

Perhaps you could provide a small reproducer?

Hi @geoand, I've started a new project and wasn't able to reproduce also. I'm adding my libs one by one to check which one brings this problem.

I'll let you know when done.

Thanks.

@geoand the problem happens when I add this dependency:

<dependency>
      <groupId>com.monitorjbl</groupId>
      <artifactId>xlsx-streamer</artifactId>
      <version>2.1.0</version>
    </dependency>

I'm checking here why.

@geoand you can close this one. I've found the problem. This library brings xerces and xml apis also.

<dependency>
      <groupId>com.monitorjbl</groupId>
      <artifactId>xlsx-streamer</artifactId>
      <version>2.1.0</version>
      <exclusions>
        <exclusion>
          <groupId>com.rackspace.apache</groupId>
          <artifactId>xerces2-xsd11</artifactId>
        </exclusion>
        <exclusion>
          <groupId>xml-apis</groupId>
          <artifactId>xml-apis</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

Thank you so much.

Great! Thanks for looking into it

@geoand I think I said you to close so earlier :)

See what I'm getting now after this exclusion, when trying to parse my .xlsx file:

java.lang.LinkageError: loader constraint violation: when resolving field "NODESET" of type javax.xml.namespace.QName, the class loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @34d11c92 (instance of io.quarkus.bootstrap.classloading.QuarkusClassLoader, child of 'bootstrap') of the current class, com.monitorjbl.xlsx.XmlUtils, and the class loader 'bootstrap' for the field's defining type, javax.xml.xpath.XPathConstants, have different Class objects for type javax.xml.namespace.QName

Reopening then 馃槑

Was this page helpful?
0 / 5 - 0 ratings