Skip to content

Commit 77d1241

Browse files
author
Simon Democko
committed
Add fallback to Thread Context Class Loader for resource loading
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
1 parent 08a7630 commit 77d1241

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ClasspathHelper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static String loadFileFromClasspath(String location) {
1313
String file = FilenameUtils.separatorsToUnix(location);
1414

1515
InputStream inputStream = ClasspathHelper.class.getResourceAsStream(file);
16-
16+
1717
if(inputStream == null) {
1818
inputStream = ClasspathHelper.class.getClassLoader().getResourceAsStream(file);
1919
}
@@ -22,6 +22,10 @@ public static String loadFileFromClasspath(String location) {
2222
inputStream = ClassLoader.getSystemResourceAsStream(file);
2323
}
2424

25+
if(inputStream == null) {
26+
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(file);
27+
}
28+
2529
if(inputStream != null) {
2630
try {
2731
return IOUtils.toString(inputStream);

0 commit comments

Comments
 (0)