Skip to content

Commit b464cc6

Browse files
authored
Merge 663d6aa into 7e57220
2 parents 7e57220 + 663d6aa commit b464cc6

File tree

8 files changed

+31
-14
lines changed

8 files changed

+31
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- For example, (this is already a default behavior) to redact all `TextView`s and their subclasses (`RadioButton`, `EditText`, etc.): `options.experimental.sessionReplay.addRedactViewClass("android.widget.TextView")`
2020
- If you're using code obfuscation, adjust your proguard-rules accordingly, so your custom view class name is not minified
2121
- Fix ensure Application Context is used even when SDK is initialized via Activity Context ([#3669](https://github.com/getsentry/sentry-java/pull/3669))
22+
- Fix potential ANRs due to `Calendar.getInstance` usage in Breadcrumbs constructor ([#3736](https://github.com/getsentry/sentry-java/pull/3736))
2223

2324
*Breaking changes*:
2425

sentry-android-replay/src/main/java/io/sentry/android/replay/DefaultReplayBreadcrumbConverter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public open class DefaultReplayBreadcrumbConverter : ReplayBreadcrumbConverter {
106106
}
107107
return if (!breadcrumbCategory.isNullOrEmpty()) {
108108
RRWebBreadcrumbEvent().apply {
109-
timestamp = breadcrumb.timestamp.time
110-
breadcrumbTimestamp = breadcrumb.timestamp.time / 1000.0
109+
timestamp = breadcrumb.timestampMs
110+
breadcrumbTimestamp = breadcrumb.timestampMs / 1000.0
111111
breadcrumbType = "default"
112112
category = breadcrumbCategory
113113
message = breadcrumbMessage
@@ -134,7 +134,7 @@ public open class DefaultReplayBreadcrumbConverter : ReplayBreadcrumbConverter {
134134
val httpStartTimestamp = breadcrumb.data[SpanDataConvention.HTTP_START_TIMESTAMP]
135135
val httpEndTimestamp = breadcrumb.data[SpanDataConvention.HTTP_END_TIMESTAMP]
136136
return RRWebSpanEvent().apply {
137-
timestamp = breadcrumb.timestamp.time
137+
timestamp = breadcrumb.timestampMs
138138
op = "resource.http"
139139
description = breadcrumb.data["url"] as String
140140
// can be double if it was serialized to disk

sentry-android-replay/src/main/java/io/sentry/android/replay/capture/CaptureStrategy.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ internal interface CaptureStrategy {
161161

162162
val urls = LinkedList<String>()
163163
breadcrumbs.forEach { breadcrumb ->
164-
if (breadcrumb.timestamp.time >= segmentTimestamp.time &&
165-
breadcrumb.timestamp.time < endTimestamp.time
164+
if (breadcrumb.timestampMs >= segmentTimestamp.time &&
165+
breadcrumb.timestampMs < endTimestamp.time
166166
) {
167167
val rrwebEvent = options
168168
.replayController

sentry/api/sentry.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public final class io/sentry/BaggageHeader {
9898

9999
public final class io/sentry/Breadcrumb : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
100100
public fun <init> ()V
101+
public fun <init> (J)V
101102
public fun <init> (Ljava/lang/String;)V
102103
public fun <init> (Ljava/util/Date;)V
103104
public static fun debug (Ljava/lang/String;)Lio/sentry/Breadcrumb;
@@ -111,6 +112,7 @@ public final class io/sentry/Breadcrumb : io/sentry/JsonSerializable, io/sentry/
111112
public fun getMessage ()Ljava/lang/String;
112113
public fun getOrigin ()Ljava/lang/String;
113114
public fun getTimestamp ()Ljava/util/Date;
115+
public fun getTimestampMs ()J
114116
public fun getType ()Ljava/lang/String;
115117
public fun getUnknown ()Ljava/util/Map;
116118
public static fun graphqlDataFetcher (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lio/sentry/Breadcrumb;

sentry/src/main/java/io/sentry/Breadcrumb.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public final class Breadcrumb implements JsonUnknown, JsonSerializable {
2121

2222
/** A timestamp representing when the breadcrumb occurred. */
23-
private final @NotNull Date timestamp;
23+
private final long timestamp;
2424

2525
/** If a message is provided, its rendered as text and the whitespace is preserved. */
2626
private @Nullable String message;
@@ -51,7 +51,12 @@ public final class Breadcrumb implements JsonUnknown, JsonSerializable {
5151
*
5252
* @param timestamp the timestamp
5353
*/
54+
@SuppressWarnings("JavaUtilDate")
5455
public Breadcrumb(final @NotNull Date timestamp) {
56+
this.timestamp = timestamp.getTime();
57+
}
58+
59+
public Breadcrumb(final long timestamp) {
5560
this.timestamp = timestamp;
5661
}
5762

@@ -504,7 +509,7 @@ public static Breadcrumb fromMap(
504509

505510
/** Breadcrumb ctor */
506511
public Breadcrumb() {
507-
this(DateUtils.getCurrentDateTime());
512+
this(System.currentTimeMillis());
508513
}
509514

510515
/**
@@ -522,9 +527,17 @@ public Breadcrumb(@Nullable String message) {
522527
*
523528
* @return the timestamp
524529
*/
525-
@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
530+
public long getTimestampMs() {
531+
return timestamp;
532+
}
533+
534+
/**
535+
* Returns the Breadcrumb's timestamp as java.util.Date
536+
*
537+
* @return the timestamp
538+
*/
526539
public @NotNull Date getTimestamp() {
527-
return (Date) timestamp.clone();
540+
return DateUtils.getDateTime(timestamp);
528541
}
529542

530543
/**
@@ -664,7 +677,7 @@ public boolean equals(Object o) {
664677
if (this == o) return true;
665678
if (o == null || getClass() != o.getClass()) return false;
666679
Breadcrumb that = (Breadcrumb) o;
667-
return timestamp.getTime() == that.timestamp.getTime()
680+
return timestamp == that.timestamp
668681
&& Objects.equals(message, that.message)
669682
&& Objects.equals(type, that.type)
670683
&& Objects.equals(category, that.category)
@@ -704,7 +717,7 @@ public static final class JsonKeys {
704717
public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger logger)
705718
throws IOException {
706719
writer.beginObject();
707-
writer.name(JsonKeys.TIMESTAMP).value(logger, timestamp);
720+
writer.name(JsonKeys.TIMESTAMP).value(logger, DateUtils.getDateTime(timestamp));
708721
if (message != null) {
709722
writer.name(JsonKeys.MESSAGE).value(message);
710723
}

sentry/src/main/java/io/sentry/SentryClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ private static final class SortBreadcrumbsByDate implements Comparator<Breadcrum
12141214
@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
12151215
@Override
12161216
public int compare(final @NotNull Breadcrumb b1, final @NotNull Breadcrumb b2) {
1217-
return b1.getTimestamp().compareTo(b2.getTimestamp());
1217+
return Long.compare(b1.getTimestampMs(), b2.getTimestampMs());
12181218
}
12191219
}
12201220
}

sentry/src/test/java/io/sentry/BreadcrumbTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import kotlin.test.assertFalse
66
import kotlin.test.assertNotNull
77
import kotlin.test.assertNotSame
88
import kotlin.test.assertNull
9+
import kotlin.test.assertTrue
910

1011
class BreadcrumbTest {
1112

@@ -97,7 +98,7 @@ class BreadcrumbTest {
9798
@Test
9899
fun `breadcrumb has timestamp when created`() {
99100
val breadcrumb = Breadcrumb()
100-
assertNotNull(breadcrumb.timestamp)
101+
assertTrue(breadcrumb.timestampMs > 0)
101102
}
102103

103104
@Test

sentry/src/test/java/io/sentry/protocol/BreadcrumbSerializationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class BreadcrumbSerializationTest {
6666
val actual = Breadcrumb.fromMap(map, SentryOptions())
6767
val expected = fixture.getSut()
6868

69-
assertEquals(expected.timestamp, actual?.timestamp)
69+
assertEquals(expected.timestampMs, actual?.timestampMs)
7070
assertEquals(expected.message, actual?.message)
7171
assertEquals(expected.type, actual?.type)
7272
assertEquals(expected.data, actual?.data)

0 commit comments

Comments
 (0)