diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/xml/XmlParserHelper.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/xml/XmlParserHelper.java index 5351fa12a3..e13929c39a 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/xml/XmlParserHelper.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/util/xml/XmlParserHelper.java @@ -9,6 +9,7 @@ package org.hibernate.processor.util.xml; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import javax.tools.FileObject; @@ -120,7 +121,14 @@ public class XmlParserHelper { ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler(); try { staxEventReader = new JpaNamespaceTransformingEventReader( staxEventReader ); - JAXBContext jaxbContext = JAXBContext.newInstance( ObjectFactory.class ); + + // Class.getClassLoader() may return null if the class was loaded by the bootstrap class loader, + // but since we don't expect the annotation processor to be loaded by that class loader, + // we expect the return to be non-null and hence cast + ClassLoader cl = NullnessUtil.castNonNull( ObjectFactory.class.getClassLoader() ); + String packageName = NullnessUtil.castNonNull( ObjectFactory.class.getPackage() ).getName(); + JAXBContext jaxbContext = JAXBContext.newInstance( packageName, cl ); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema( schema ); unmarshaller.setEventHandler( handler );