Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@QuarkusTest classloader problems when executing XPathFactory.newInstance() #8451

Open
diogocarleto opened this issue Apr 7, 2020 · 9 comments
Labels
area/testing kind/bug Something isn't working

Comments

@diogocarleto
Copy link
Contributor

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.

@diogocarleto diogocarleto added the kind/bug Something isn't working label Apr 7, 2020
@geoand
Copy link
Contributor

geoand commented Apr 7, 2020

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

Perhaps you could provide a small reproducer?

@diogocarleto
Copy link
Contributor Author

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.

@diogocarleto
Copy link
Contributor Author

diogocarleto commented Apr 7, 2020

@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.

@diogocarleto
Copy link
Contributor Author

diogocarleto commented Apr 7, 2020

@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.

@geoand
Copy link
Contributor

geoand commented Apr 7, 2020

Great! Thanks for looking into it

@geoand geoand closed this as completed Apr 7, 2020
@geoand geoand added the triage/invalid This doesn't seem right label Apr 7, 2020
@diogocarleto
Copy link
Contributor Author

diogocarleto commented Apr 7, 2020

@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

@geoand geoand reopened this Apr 7, 2020
@geoand geoand removed the triage/invalid This doesn't seem right label Apr 7, 2020
@geoand
Copy link
Contributor

geoand commented Apr 7, 2020

Reopening then 😎

@jzampieron
Copy link

There are also similar problems with XPathFactory.newDefaultInstance() in certain build/run scenarios.

We get no-such-method errors in certain builds (e.g. w/ Xerces present) for the above method.

When packaging the apps to a fast-jar it appears as if the Quarkus Classloader will not always load from the "default" JRE library set.

This is pretty clearly a bug in either the Quarkus build tooling and/or the Quarkus Classloader.

Libraries available in the system JRE should, by definition, never throw a ClassNotFound or NoSuchMethod error... if they do, that ClassLoader is either "special" and shouldn't happen without explicit request and/or broken.

Now interactions and behavior in native builds probably need very explicit definition in these cases.

@dmlloyd
Copy link
Member

dmlloyd commented Jun 11, 2024

There is a chance that this is related to #40601. Linking it to double-check later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants