Skip to content

Commit d39edd7

Browse files
authored
Merge 8812916 into 320aa5a
2 parents 320aa5a + 8812916 commit d39edd7

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ public void store(final @NotNull SentryEnvelope envelope, final @NotNull Hint hi
174174
} else {
175175
options
176176
.getLogger()
177-
.log(DEBUG, "Adding Envelope to offline storage: %s", envelopeFile.getAbsolutePath());
177+
.log(
178+
DEBUG,
179+
new Exception(),
180+
"Adding Envelope to offline storage: %s",
181+
envelopeFile.getAbsolutePath());
178182
}
179183

180184
writeEnvelopeToDisk(envelopeFile, envelope);
@@ -362,16 +366,11 @@ public void discard(final @NotNull SentryEnvelope envelope) {
362366
* @return the file
363367
*/
364368
private synchronized @NotNull File getEnvelopeFile(final @NotNull SentryEnvelope envelope) {
365-
String fileName;
369+
final @NotNull String fileName;
366370
if (fileNameMap.containsKey(envelope)) {
367371
fileName = fileNameMap.get(envelope);
368372
} else {
369-
if (envelope.getHeader().getEventId() != null) {
370-
fileName = envelope.getHeader().getEventId().toString();
371-
} else {
372-
fileName = UUID.randomUUID().toString();
373-
}
374-
fileName += SUFFIX_ENVELOPE_FILE;
373+
fileName = UUID.randomUUID() + SUFFIX_ENVELOPE_FILE;
375374
fileNameMap.put(envelope, fileName);
376375
}
377376

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)