diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fb750f4f..6e495e829e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Fix concurrent access to frameMetrics listener ([#2823](https://github.com/getsentry/sentry-java/pull/2823)) + ## 6.25.0 ### Features diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java b/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java index 7eb2f2b010..f8957982e7 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/internal/util/SentryFrameMetricsCollector.java @@ -19,10 +19,11 @@ import io.sentry.util.Objects; import java.lang.ref.WeakReference; import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,12 +31,12 @@ @ApiStatus.Internal public final class SentryFrameMetricsCollector implements Application.ActivityLifecycleCallbacks { private final @NotNull BuildInfoProvider buildInfoProvider; - private final @NotNull Set trackedWindows = new HashSet<>(); + private final @NotNull Set trackedWindows = new CopyOnWriteArraySet<>(); private final @NotNull SentryOptions options; private @Nullable Handler handler; private @Nullable WeakReference currentWindow; - private final @NotNull HashMap listenerMap = - new HashMap<>(); + private final @NotNull Map listenerMap = + new ConcurrentHashMap<>(); private boolean isAvailable = false; private final WindowFrameMetricsManager windowFrameMetricsManager;