Skip to content

Commit 61f1ea9

Browse files
ref(cache): fold the session-id comparison into one predicate
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 00a36b6 commit 61f1ea9

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,19 +339,16 @@ private void writeCrashMarkerFile() {
339339
* #persistCurrentSession(Session)} can have put it there, writing the live session, so the stored
340340
* copy is at least as advanced as this envelope. Rotating and overwriting it would file a running
341341
* session as the previous one and roll back any unhandled error it has recorded since.
342+
*
343+
* <p>A null session id never matches, so sessions we cannot tell apart are rotated as before.
342344
*/
343345
private boolean isLateDuplicateStart(
344346
final @Nullable Session startingSession, final @Nullable Session currentSession) {
345-
return startingSession != null
346-
&& currentSession != null
347-
&& hasSameSessionId(currentSession, startingSession);
348-
}
349-
350-
private boolean hasSameSessionId(
351-
final @NotNull Session firstSession, final @NotNull Session secondSession) {
352-
return firstSession.getSessionId() != null
353-
&& secondSession.getSessionId() != null
354-
&& Objects.equals(firstSession.getSessionId(), secondSession.getSessionId());
347+
if (startingSession == null || currentSession == null) {
348+
return false;
349+
}
350+
final @Nullable String startingSessionId = startingSession.getSessionId();
351+
return startingSessionId != null && startingSessionId.equals(currentSession.getSessionId());
355352
}
356353

357354
private boolean writeEnvelopeToDisk(

0 commit comments

Comments
 (0)