From b7797f9e8d9cc96c6867c214279c0a789ba3cf26 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 3 Aug 2022 08:34:26 +0200 Subject: [PATCH 1/2] Prevent NPE by checking SentryTracer.timer for null again inside synchronized --- sentry/src/main/java/io/sentry/SentryTracer.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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; + } } } From 7cab097b900155a395488777baf50909322af4ce Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Wed, 3 Aug 2022 08:43:19 +0200 Subject: [PATCH 2/2] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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))