Skip to content

Commit 7ab32b6

Browse files
authored
Fix UserFeedback disk cache name conflicts with linked events (#3116)
* Fix UserFeedback cache name conflicts with attached Event cache file name * Add Changelog * Remove uneccesary Exception * Fix method doc * Update CHANGELOG.md * Update CHANGELOG.md
1 parent 0816a48 commit 7ab32b6

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Fix not eligible for auto proxying warnings ([#3154](https://github.com/getsentry/sentry-java/pull/3154))
2222
- Set default fingerprint for ANRv2 events to correctly group background and foreground ANRs ([#3164](https://github.com/getsentry/sentry-java/pull/3164))
2323
- This will improve grouping of ANRs that have similar stacktraces but differ in background vs foreground state. Only affects newly-ingested ANR events with `mechanism:AppExitInfo`
24+
- Fix UserFeedback disk cache name conflicts with linked events ([#3116](https://github.com/getsentry/sentry-java/pull/3116))
2425

2526
### Breaking changes
2627

sentry/src/main/java/io/sentry/cache/EnvelopeCache.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,23 +353,18 @@ public void discard(final @NotNull SentryEnvelope envelope) {
353353
}
354354

355355
/**
356-
* Returns the envelope's file path. If the envelope has no eventId header, it generates a random
357-
* file name to it.
356+
* Returns the envelope's file path. If the envelope wasn't added to the cache beforehand, a
357+
* random file name is assigned.
358358
*
359359
* @param envelope the SentryEnvelope object
360360
* @return the file
361361
*/
362362
private synchronized @NotNull File getEnvelopeFile(final @NotNull SentryEnvelope envelope) {
363-
String fileName;
363+
final @NotNull String fileName;
364364
if (fileNameMap.containsKey(envelope)) {
365365
fileName = fileNameMap.get(envelope);
366366
} else {
367-
if (envelope.getHeader().getEventId() != null) {
368-
fileName = envelope.getHeader().getEventId().toString();
369-
} else {
370-
fileName = UUID.randomUUID().toString();
371-
}
372-
fileName += SUFFIX_ENVELOPE_FILE;
367+
fileName = UUID.randomUUID() + SUFFIX_ENVELOPE_FILE;
373368
fileNameMap.put(envelope, fileName);
374369
}
375370

sentry/src/test/java/io/sentry/cache/EnvelopeCacheTest.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.cache
22

33
import io.sentry.DateUtils
4+
import io.sentry.Hint
45
import io.sentry.ILogger
56
import io.sentry.NoOpLogger
67
import io.sentry.SentryCrashLastRunState
@@ -16,6 +17,7 @@ import io.sentry.cache.EnvelopeCache.SUFFIX_SESSION_FILE
1617
import io.sentry.hints.AbnormalExit
1718
import io.sentry.hints.SessionEndHint
1819
import io.sentry.hints.SessionStartHint
20+
import io.sentry.protocol.SentryId
1921
import io.sentry.util.HintUtils
2022
import org.mockito.kotlin.mock
2123
import java.io.File
@@ -317,4 +319,32 @@ class EnvelopeCacheTest {
317319
null
318320
)
319321
}
322+
323+
@Test
324+
fun `two items with the same event id can be stored side-by-side`() {
325+
val cache = fixture.getSUT()
326+
327+
val eventId = SentryId()
328+
329+
val envelopeA = SentryEnvelope.from(
330+
fixture.options.serializer,
331+
SentryEvent().apply {
332+
setEventId(eventId)
333+
},
334+
null
335+
)
336+
337+
val envelopeB = SentryEnvelope.from(
338+
fixture.options.serializer,
339+
SentryEvent().apply {
340+
setEventId(eventId)
341+
},
342+
null
343+
)
344+
345+
cache.store(envelopeA, Hint())
346+
cache.store(envelopeB, Hint())
347+
348+
assertEquals(2, cache.directory.list()?.size)
349+
}
320350
}

0 commit comments

Comments
 (0)