Skip to content

Commit 421676c

Browse files
authored
Merge pull request #34 from luiseufrasio/FISH-9551-avoiding-npe
Fish 9551 avoiding npe
2 parents 5aad3f7 + bc28d06 commit 421676c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

moxy/org.eclipse.persistence.moxy/src/main/java/org/eclipse/persistence/jaxb/ValidationXMLReader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public Map<Class<?>, Boolean> call() throws Exception {
9494
* Checks if validation.xml exists.
9595
*/
9696
public static boolean isValidationXmlPresent() {
97-
return getThreadContextClassLoader().getResource(VALIDATION_XML) != null;
97+
ClassLoader threadContextClassLoader = getThreadContextClassLoader();
98+
return threadContextClassLoader != null && threadContextClassLoader.getResource(VALIDATION_XML) != null;
9899
}
99100

100101
private void parseConstraintFiles() {
@@ -170,7 +171,14 @@ private void parseValidationXML(String constraintsFilePath, DefaultHandler handl
170171

171172
private static ClassLoader getThreadContextClassLoader() {
172173
return PrivilegedAccessHelper.callDoPrivileged(
173-
() -> Thread.currentThread().getContextClassLoader()
174+
() -> {
175+
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
176+
if (classLoader == null) {
177+
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
178+
classLoader = Thread.currentThread().getContextClassLoader();
179+
}
180+
return classLoader;
181+
}
174182
);
175183
}
176184

0 commit comments

Comments
 (0)