Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Fix not eligible for auto proxying warnings ([#3154](https://github.com/getsentry/sentry-java/pull/3154))
- Set default fingerprint for ANRv2 events to correctly group background and foreground ANRs ([#3164](https://github.com/getsentry/sentry-java/pull/3164))
- 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`
- Fix UserFeedback disk cache name conflicts with linked events ([#3116](https://github.com/getsentry/sentry-java/pull/3116))

### Breaking changes

Expand Down
13 changes: 4 additions & 9 deletions sentry/src/main/java/io/sentry/cache/EnvelopeCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -353,23 +353,18 @@ public void discard(final @NotNull SentryEnvelope envelope) {
}

/**
* Returns the envelope's file path. If the envelope has no eventId header, it generates a random
* file name to it.
* Returns the envelope's file path. If the envelope wasn't added to the cache beforehand, a
* random file name is assigned.
*
* @param envelope the SentryEnvelope object
* @return the file
*/
private synchronized @NotNull File getEnvelopeFile(final @NotNull SentryEnvelope envelope) {
String fileName;
final @NotNull String fileName;
if (fileNameMap.containsKey(envelope)) {
fileName = fileNameMap.get(envelope);
} else {
if (envelope.getHeader().getEventId() != null) {
fileName = envelope.getHeader().getEventId().toString();
} else {
fileName = UUID.randomUUID().toString();
}
fileName += SUFFIX_ENVELOPE_FILE;
fileName = UUID.randomUUID() + SUFFIX_ENVELOPE_FILE;
fileNameMap.put(envelope, fileName);
}

Expand Down
30 changes: 30 additions & 0 deletions sentry/src/test/java/io/sentry/cache/EnvelopeCacheTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sentry.cache

import io.sentry.DateUtils
import io.sentry.Hint
import io.sentry.ILogger
import io.sentry.NoOpLogger
import io.sentry.SentryCrashLastRunState
Expand All @@ -16,6 +17,7 @@ import io.sentry.cache.EnvelopeCache.SUFFIX_SESSION_FILE
import io.sentry.hints.AbnormalExit
import io.sentry.hints.SessionEndHint
import io.sentry.hints.SessionStartHint
import io.sentry.protocol.SentryId
import io.sentry.util.HintUtils
import org.mockito.kotlin.mock
import java.io.File
Expand Down Expand Up @@ -317,4 +319,32 @@ class EnvelopeCacheTest {
null
)
}

@Test
fun `two items with the same event id can be stored side-by-side`() {
val cache = fixture.getSUT()

val eventId = SentryId()

val envelopeA = SentryEnvelope.from(
fixture.options.serializer,
SentryEvent().apply {
setEventId(eventId)
},
null
)

val envelopeB = SentryEnvelope.from(
fixture.options.serializer,
SentryEvent().apply {
setEventId(eventId)
},
null
)

cache.store(envelopeA, Hint())
cache.store(envelopeB, Hint())

assertEquals(2, cache.directory.list()?.size)
}
}