Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
ContextFinder falls back to context classloader resulting in class cast errors #121
When we call
Given that the context classloader can be "higher" in the chain of classloaders than the current class's classloader and that, since the jaxb-api is no longer part of java core, this might mean that the
This means that if we end up at line 362 and 363 of
we might end up with a
I ran into this issue while using javax.xml.bind:jaxb-api:2.3.1 on JDK 11 (specifically, while trying to read a persistence.xml using the hibernate jpa metamodel generator through the maven processor plugin). Some more detail on the hibernate jira HHH-13794 and in my blog post.
I ended up with a stacktrace like:
I see no reason why this wouldn't fail with the current version of jaxb-api but I haven't yet been able to test it. I think this will fail any time where the JAXBContext as used in ContextFinder gets loaded on a classloader that is not the current thread's context classloader.
Constructing a testcase is somewhat less trivial since you have to make sure that the classloaders are configured correctly. I'm fairly certain that the testcase I provided for HHH-13794](https://hibernate.atlassian.net/browse/HHH-13794) would work for (or be easily adapted to) the current jakarta jaxb-api.
Update: I tested the testcase in HHH-13794 against jakarta.xml.bind:jakarta.xml.bind-api:2.3.2 and the error was there as well.
This issue is similar to, though definitely not the same as, #99.
I propose two solutions to mitigate this issue: