Skip to content

Commit

Permalink
FISH-9551 : trying to avoid NPE in Linux when classloader config is n…
Browse files Browse the repository at this point in the history
…ot found
  • Loading branch information
luiseufrasio committed Sep 22, 2024
1 parent 5aad3f7 commit bc28d06
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public Map<Class<?>, 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() {
Expand Down Expand Up @@ -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;
}
);
}

Expand Down

0 comments on commit bc28d06

Please sign in to comment.