diff --git a/moxy/org.eclipse.persistence.moxy/src/main/java/org/eclipse/persistence/jaxb/ValidationXMLReader.java b/moxy/org.eclipse.persistence.moxy/src/main/java/org/eclipse/persistence/jaxb/ValidationXMLReader.java index e7e049674ca..59123f26f94 100644 --- a/moxy/org.eclipse.persistence.moxy/src/main/java/org/eclipse/persistence/jaxb/ValidationXMLReader.java +++ b/moxy/org.eclipse.persistence.moxy/src/main/java/org/eclipse/persistence/jaxb/ValidationXMLReader.java @@ -94,7 +94,8 @@ public Map, Boolean> call() throws Exception { * Checks if validation.xml exists. */ public static boolean isValidationXmlPresent() { - return getThreadContextClassLoader().getResource(VALIDATION_XML) != null; + ClassLoader threadContextClassLoader = getThreadContextClassLoader(); + return threadContextClassLoader != null && threadContextClassLoader.getResource(VALIDATION_XML) != null; } private void parseConstraintFiles() { @@ -170,7 +171,14 @@ private void parseValidationXML(String constraintsFilePath, DefaultHandler handl private static ClassLoader getThreadContextClassLoader() { return PrivilegedAccessHelper.callDoPrivileged( - () -> Thread.currentThread().getContextClassLoader() + () -> { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + if (classLoader == null) { + Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader()); + classLoader = Thread.currentThread().getContextClassLoader(); + } + return classLoader; + } ); }