Skip to content

Commit

Permalink
Add fallback to Thread Context Class Loader for resource loading
Browse files Browse the repository at this point in the history
This commit adds a fallback to `Thread.currentThread().getContextClassLoader().getResourceAsStream(file)` in the `ClasspathHelper` class.

Previously, if the `ClasspathHelper.class.getResourceAsStream(file)` and `ClassLoader.getSystemResourceAsStream(file)` methods returned `null`, no further attempts were made to load the resource, which caused issues in Quarkus applications in dev mode.

This commit adds an additional fallback to `Thread.currentThread().getContextClassLoader().getResourceAsStream(file)` to improve compatibility with the Quarkus class loading model.

Related Issue: #1968
  • Loading branch information
Simon Democko committed Aug 29, 2023
1 parent 08a7630 commit 77d1241
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static String loadFileFromClasspath(String location) {
String file = FilenameUtils.separatorsToUnix(location);

InputStream inputStream = ClasspathHelper.class.getResourceAsStream(file);

if(inputStream == null) {
inputStream = ClasspathHelper.class.getClassLoader().getResourceAsStream(file);
}
Expand All @@ -22,6 +22,10 @@ public static String loadFileFromClasspath(String location) {
inputStream = ClassLoader.getSystemResourceAsStream(file);
}

if(inputStream == null) {
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
}

if(inputStream != null) {
try {
return IOUtils.toString(inputStream);
Expand Down

0 comments on commit 77d1241

Please sign in to comment.