From be2cd4ebf9782eeba90f0b8a6c2d07a2408b4239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Wed, 21 Aug 2024 16:56:45 +0200 Subject: [PATCH] Fix concurrent modification when creating TrackerEvent by copying the payload (close #692) --- .../com/snowplowanalytics/core/tracker/TrackerEvent.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerEvent.kt b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerEvent.kt index f5e5e7185..3967b9ab9 100644 --- a/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerEvent.kt +++ b/snowplow-tracker/src/main/java/com/snowplowanalytics/core/tracker/TrackerEvent.kt @@ -43,8 +43,12 @@ class TrackerEvent @JvmOverloads constructor(event: Event, state: TrackerStateSn init { entities = event.entities.toMutableList() trueTimestamp = event.trueTimestamp - payload = HashMap(event.dataPayload) - + // NOTE: this code is a workaround since the types of the `Event.dataPayload` and `TrackerEvent.payload` don't match + // `Event` allows the values to be optional, while `TrackerEvent` does not. + // We should fix this in the next major version to unify the types. + // The `toMap()` is called in order to make a copy before calling HashMap as that can lead to concurrency issues, see #692 + payload = HashMap(event.dataPayload.toMap()) + if (state != null) { this.state = state } else {