Skip to content

Commit da73506

Browse files
ref(session): drop the private canonical constructor
hasNonTerminatingUnhandledError is not final - recordNonTerminating UnhandledError and update() both write it - so setting it through a constructor established no invariant that a plain assignment does not. Both call sites are inside Session, so clone() and the deserializer can assign the field directly, which is what the deserializer already does for unknown. Removes the 15-parameter overload and the javadoc that existed to justify it. The public constructor is unchanged, so sentry.api is too. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c959b0a commit da73506

1 file changed

Lines changed: 20 additions & 59 deletions

File tree

‎sentry/src/main/java/io/sentry/Session.java‎

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -91,46 +91,6 @@ public Session(
9191
final @Nullable String environment,
9292
final @NotNull String release,
9393
final @Nullable String abnormalMechanism) {
94-
this(
95-
status,
96-
started,
97-
timestamp,
98-
errorCount,
99-
distinctId,
100-
sessionId,
101-
init,
102-
sequence,
103-
duration,
104-
ipAddress,
105-
userAgent,
106-
environment,
107-
release,
108-
abnormalMechanism,
109-
false);
110-
}
111-
112-
/**
113-
* Canonical constructor. Kept private so {@code hasNonTerminatingUnhandledError} stays off the
114-
* public API: it is internal bookkeeping that only {@link #clone()} and {@link Deserializer} need
115-
* to restore, and a public overload carrying it would let callers fabricate a session claiming an
116-
* unhandled error that was never counted.
117-
*/
118-
private Session(
119-
final @NotNull State status,
120-
final @NotNull Date started,
121-
final @Nullable Date timestamp,
122-
final int errorCount,
123-
final @Nullable String distinctId,
124-
final @Nullable String sessionId,
125-
final @Nullable Boolean init,
126-
final @Nullable Long sequence,
127-
final @Nullable Double duration,
128-
final @Nullable String ipAddress,
129-
final @Nullable String userAgent,
130-
final @Nullable String environment,
131-
final @NotNull String release,
132-
final @Nullable String abnormalMechanism,
133-
final boolean hasNonTerminatingUnhandledError) {
13494
this.status = status;
13595
this.started = started;
13696
this.timestamp = timestamp;
@@ -145,7 +105,6 @@ private Session(
145105
this.environment = environment;
146106
this.release = release;
147107
this.abnormalMechanism = abnormalMechanism;
148-
this.hasNonTerminatingUnhandledError = hasNonTerminatingUnhandledError;
149108
}
150109

151110
public Session(
@@ -403,22 +362,24 @@ private long getSequenceTimestamp(final @NotNull Date timestamp) {
403362
*/
404363
@SuppressWarnings("MissingOverride")
405364
public @NotNull Session clone() {
406-
return new Session(
407-
status,
408-
started,
409-
timestamp,
410-
errorCount.get(),
411-
distinctId,
412-
sessionId,
413-
init,
414-
sequence,
415-
duration,
416-
ipAddress,
417-
userAgent,
418-
environment,
419-
release,
420-
abnormalMechanism,
421-
hasNonTerminatingUnhandledError);
365+
final @NotNull Session session =
366+
new Session(
367+
status,
368+
started,
369+
timestamp,
370+
errorCount.get(),
371+
distinctId,
372+
sessionId,
373+
init,
374+
sequence,
375+
duration,
376+
ipAddress,
377+
userAgent,
378+
environment,
379+
release,
380+
abnormalMechanism);
381+
session.hasNonTerminatingUnhandledError = hasNonTerminatingUnhandledError;
382+
return session;
422383
}
423384

424385
// JsonSerializable
@@ -638,8 +599,8 @@ public static final class Deserializer implements JsonDeserializer<Session> {
638599
userAgent,
639600
environment,
640601
release,
641-
abnormalMechanism,
642-
hasNonTerminatingUnhandledError);
602+
abnormalMechanism);
603+
session.hasNonTerminatingUnhandledError = hasNonTerminatingUnhandledError;
643604
session.setUnknown(unknown);
644605
reader.endObject();
645606
return session;

0 commit comments

Comments
 (0)