[BUILD-462] JAXBException when using Java 11 Created: 06/May/21  Updated: 17/May/21  Resolved: 07/May/21

Status: Closed
Project: Build
Component/s: None
Affects Version/s: BOM 6.2.8
Fix Version/s: BOM 6.2.9

Type: Bug Priority: Neutral
Reporter: Jonathan Ayala Assignee: Federico Grilli
Resolution: Fixed Votes: 0
Labels: maintenance, regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screenshot 2021-05-07 at 08.37.32.png    
Issue Links:
Problem/Incident
causality
Template:
Acceptance criteria:
Empty
Release notes required:
Yes
Date of First Response:
Sprint: Maintenance 56
Story Points: 1

 Description   

Steps to reproduce

  1.  Start Magnolia 6.2.8 using Java 11
  2.  Call the rest endpoint: http://<localhost:8080>/magnoliaAuthor/.rest/nodes/v1/website/sportstation

Expected results

The Rest endpoint is correctly called and response is shown in the browser

Actual results

There's an error:

ERROR info.magnolia.rest.RestExceptionMapper            : Exception thrown executing REST endpoint, returning 500
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278) ~[jaxb-api-2.3.1.jar:2.3.0]
	at javax.xml.bind.ContextFinder.find(ContextFinder.java:421) ~[jaxb-api-2.3.1.jar:2.3.0]
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721) ~[jaxb-api-2.3.1.jar:2.3.0]
	at org.jboss.resteasy.plugins.providers.jaxb.JAXBContextWrapper.<init>(JAXBContextWrapper.java:112) ~[resteasy-jaxb-provider-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.providers.jaxb.JAXBContextWrapper.<init>(JAXBContextWrapper.java:175) ~[resteasy-jaxb-provider-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.providers.jaxb.XmlJAXBContextFinder.createContextObject(XmlJAXBContextFinder.java:52) ~[resteasy-jaxb-provider-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBContextFinder.createContext(AbstractJAXBContextFinder.java:173) ~[resteasy-jaxb-provider-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.providers.jaxb.XmlJAXBContextFinder.findCachedContext(XmlJAXBContextFinder.java:41) ~[resteasy-jaxb-provider-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.findJAXBContext(AbstractJAXBProvider.java:84) ~[resteasy-jaxb-provider-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.getMarshaller(AbstractJAXBProvider.java:174) ~[resteasy-jaxb-provider-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:150) ~[resteasy-jaxb-provider-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.messagebody.AsyncBufferedMessageBodyWriter.asyncWriteTo(AsyncBufferedMessageBodyWriter.java:24) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.interception.jaxrs.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:87) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.interception.jaxrs.AbstractWriterInterceptorContext.asyncProceed(AbstractWriterInterceptorContext.java:203) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.interception.jaxrs.AbstractWriterInterceptorContext.getStarted(AbstractWriterInterceptorContext.java:166) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.interception.jaxrs.ServerWriterInterceptorContext.lambda$getStarted$0(ServerWriterInterceptorContext.java:73) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.interception.jaxrs.ServerWriterInterceptorContext.aroundWriteTo(ServerWriterInterceptorContext.java:93) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.interception.jaxrs.ServerWriterInterceptorContext.getStarted(ServerWriterInterceptorContext.java:73) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.ServerResponseWriter.lambda$writeNomapResponse$3(ServerResponseWriter.java:163) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.interception.jaxrs.ContainerResponseContextImpl.filter(ContainerResponseContextImpl.java:404) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.ServerResponseWriter.executeFilters(ServerResponseWriter.java:252) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:101) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:74) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:594) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:524) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161) ~[resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364) [resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164) [resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247) [resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:249) [resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:60) [resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-core-4.5.8.Final.jar:4.5.8.Final]
	...
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1364) ~[catalina.jar:9.0.43]
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1187) ~[catalina.jar:9.0.43]
	at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122) ~[jaxb-api-2.3.1.jar:2.3.0]
	at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155) ~[jaxb-api-2.3.1.jar:2.3.0]
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276) ~[jaxb-api-2.3.1.jar:2.3.0]
	... 148 more
 

Workaround

As a workaround before 6.2.9 release, one could override jaxb-runtime version in their project pom, e.g.

<dependency>
      <groupId>info.magnolia.bundle</groupId>
      <artifactId>magnolia-community-webapp</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>info.magnolia.bundle</groupId>
      <artifactId>magnolia-community-webapp</artifactId>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-runtime</artifactId>
      <version>2.3.3-b02</version>
      <exclusions>
        <exclusion>
          <groupId>javax.activation</groupId>
          <artifactId>javax.activation-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>jakarta.xml.bind</groupId>
          <artifactId>jakarta.xml.bind-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  • Alternatively, use Java 8

Development notes

This is happening due to the update of jaxb-runtime to 3.0.0 in Magnolia 6.2.8 when using java 11. If using java 8 it works (see https://stackoverflow.com/questions/43574426/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception)

In Magnolia 6.2.7 there's no error. 

The issue was caused by Tika update to version 1.26 which pulled in jaxb-runtime 3.0.0 
Fix will consist in excluding jaxb-runtime from Tika parsers, as we do already for other jaxb libraries and let RESTEasy manage those dependencies.



 Comments   
Comment by Mikaël Geljić [ 06/May/21 ]

Who updated jaxb runtime to 3.0.0, Tika or us? That looks wrong because 3.0.0 is the version "repackaged" for Jakarta EE 9. For 6.2 series, we are capped at Jakarta EE 8 with the older javax package coordinates. That looks to be 2.3.2 for JAXB.

<dependency>
  <groupId>jakarta.xml.bind</groupId>
  <artifactId>jakarta.xml.bind-api</artifactId>
  <version>2.3.2</version>
</dependency>

https://github.com/eclipse-ee4j/jakartaee-api/blob/8.0.x-BRANCH/pom.xml#L85

Comment by Federico Grilli [ 06/May/21 ]

mgeljicTika did :feelsbadman:

Comment by Mercedes Iruela [ 07/May/21 ]

FYI, this issue is not reproducible in our demo: https://demoauthor.magnolia-cms.com/.rest/nodes/v1/website/sportstation , so might it be related to some specific version of JDK 11?

Comment by Federico Grilli [ 07/May/21 ]

miruela Possibly but, afaik, JDK 11 removed JAXB APIs for good. Perhaps, in the case of the demo webapp, we're just lucky and some other module (not present in dx-core) pulls in jaxb-runtime 2.x (or excludes version 3.0.0).

Comment by Mercedes Iruela [ 07/May/21 ]

Good point, you might be right.

Comment by Mikaël Geljić [ 07/May/21 ]

For the record, the problem was not about jaxb-api but about the glassfish jaxb-runtime implementation, with Tika's 3.0.0 taking precedence over RESTEasy's 2.3.x. See the updated description.

Demo is the outlier—jaxb-runtime is unmanaged, ecommerce pulls it via resteasy and makes it more shallow in the dep-tree than tika-parsers, so we're "lucky" there. Meanwhile dx-core, dx-core-demo and dx-core-cloud are all affected.

Managing jaxb-runtime (why not in addition to the exclusion from tika) in sync w/ RESTEasy sounds like a good measure then, not to be affected by varying depth at which that dep is found.

Generated at Sun Feb 11 23:42:07 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.