Skip to content

Commit 4eb446a

Browse files
authored
Prevent NPE by checking SentryTracer.timer for null again inside synchronized (#2200)
1 parent 2759ef9 commit 4eb446a

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Fixes
66

7+
- Prevent NPE by checking SentryTracer.timer for null again inside synchronized ([#2200](https://github.com/getsentry/sentry-java/pull/2200))
78
- `attach-screenshot` set on Manual init. didn't work ([#2186](https://github.com/getsentry/sentry-java/pull/2186))
89
- Remove extra space from `spring.factories` causing issues in old versions of Spring Boot ([#2181](https://github.com/getsentry/sentry-java/pull/2181))
910

sentry/src/main/java/io/sentry/SentryTracer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public final class SentryTracer implements ITransaction {
6464
*/
6565
private final @Nullable Long idleTimeout;
6666

67-
private @Nullable TimerTask timerTask;
68-
private @Nullable Timer timer = null;
67+
private volatile @Nullable TimerTask timerTask;
68+
private volatile @Nullable Timer timer = null;
6969
private final @NotNull Object timerLock = new Object();
7070
private final @NotNull SpanByTimestampComparator spanByTimestampComparator =
7171
new SpanByTimestampComparator();
@@ -344,8 +344,10 @@ public void finish(@Nullable SpanStatus status) {
344344

345345
if (timer != null) {
346346
synchronized (timerLock) {
347-
timer.cancel();
348-
timer = null;
347+
if (timer != null) {
348+
timer.cancel();
349+
timer = null;
350+
}
349351
}
350352
}
351353

0 commit comments

Comments
 (0)