Skip to content

Commit 286b57f

Browse files
acmilcian
andauthored
Use thread context classloader when available (#4320)
* Use thread context classloader when available * ./gradlew spotlessApply * changelog * Update CHANGELOG.md --------- Co-authored-by: lcian <lorenzo.cian@sentry.io> Co-authored-by: Lorenzo Cian <cian.lorenzo@gmail.com>
1 parent e42930f commit 286b57f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Use thread context classloader when available ([#4320](https://github.com/getsentry/sentry-java/pull/4320))
8+
- This ensures correct resource loading in environments like Spring Boot where the thread context classloader is used for resource loading.
9+
310
## 8.7.0
411

512
### Features

sentry/src/main/java/io/sentry/util/ClassLoaderUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ public final class ClassLoaderUtils {
88
public static @NotNull ClassLoader classLoaderOrDefault(final @Nullable ClassLoader classLoader) {
99
// bootstrap classloader is represented as null, so using system classloader instead
1010
if (classLoader == null) {
11+
// try thread context classloader
12+
final @Nullable ClassLoader contextClassLoader =
13+
Thread.currentThread().getContextClassLoader();
14+
if (contextClassLoader != null) {
15+
return contextClassLoader;
16+
}
17+
// fallback to system classloader
1118
return ClassLoader.getSystemClassLoader();
1219
} else {
1320
return classLoader;

0 commit comments

Comments
 (0)