The behavior of the ClassLoader used by JAXBContext inside a plugin seems to have changed from Jira 7.x to 8.x.
Running a simple test like this in a plugin:
JAXBContext context = JAXBContext.newInstance(“com.acme.foo”);
log.debug(“classloader for context: {}”, context.getClass().getClassLoader());
Gives this result in Jira 7.x:
classloader for context: com.my.plugin.test-plugin [235]
and this result in Jira 8.x:
classloader for context: ParallelWebappClassLoader
context: jira
delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@6f496d9
Maybe it’s some sort of change between the versions of tomcat included with Jira. Whatever it is, it essentially renders jaxb unusable in a plugin because marshalling / setProperty can’t succeed in doing instanceof tests on classes loaded from different classloaders.
Trying to fix it by passing a ClassLoader using JAXBContext.newInstance(“com.acme.foo”, myClassLoader) doesn’t seem to change the behavior.
Has anyone else encountered this on the latest releases of Jira and found a workaround?
I think that’s a good theory. Maybe in the move to support JDK 11 which doesn’t come with JAXB included they inadvertently broke things by adding it as a dependency.
Java 11 removed JAX-B from the JDK, where javax.xml.bind and friends used to be just standard packages. As a result, in order to support Java 11, Bitbucket Server (which I work on) and Jira had to switch to bundling JAX-B libraries directly; we can’t rely on the JDK itself providing it anymore. (The other products will follow suit as they release Java 11-compatible versions.) That’s resulted in a change of behavior. Previously the javax.xml.bind bits were handled like, say, java.lang.String, but now they’re not. The JAX-B changes are causing problems for more than just Atlassian products. (See here, for example).
We’re still researching this internally… Stay tuned, and apologies for the delay.