diff --git a/CHANGELOG.md b/CHANGELOG.md index d4a71b56bc..a2f77a36bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Fixes +- Prevent NPE by checking SentryTracer.timer for null again inside synchronized ([#2200](https://github.com/getsentry/sentry-java/pull/2200)) - `attach-screenshot` set on Manual init. didn't work ([#2186](https://github.com/getsentry/sentry-java/pull/2186)) - Remove extra space from `spring.factories` causing issues in old versions of Spring Boot ([#2181](https://github.com/getsentry/sentry-java/pull/2181)) diff --git a/sentry/src/main/java/io/sentry/SentryTracer.java b/sentry/src/main/java/io/sentry/SentryTracer.java index a05d37c579..151766e53d 100644 --- a/sentry/src/main/java/io/sentry/SentryTracer.java +++ b/sentry/src/main/java/io/sentry/SentryTracer.java @@ -64,8 +64,8 @@ public final class SentryTracer implements ITransaction { */ private final @Nullable Long idleTimeout; - private @Nullable TimerTask timerTask; - private @Nullable Timer timer = null; + private volatile @Nullable TimerTask timerTask; + private volatile @Nullable Timer timer = null; private final @NotNull Object timerLock = new Object(); private final @NotNull SpanByTimestampComparator spanByTimestampComparator = new SpanByTimestampComparator(); @@ -344,8 +344,10 @@ public void finish(@Nullable SpanStatus status) { if (timer != null) { synchronized (timerLock) { - timer.cancel(); - timer = null; + if (timer != null) { + timer.cancel(); + timer = null; + } } }