Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/Breadcrumb.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public Breadcrumb(@Nullable String message) {
@SuppressWarnings("JavaUtilDate")
public @NotNull Date getTimestamp() {
if (timestamp != null) {
return (Date) timestamp.clone();
return timestamp;
} else if (timestampMs != null) {
// we memoize it here into timestamp to avoid instantiating Calendar again and again
timestamp = DateUtils.getDateTime(timestampMs);
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/SentryEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public SentryEvent(final @NotNull Date timestamp) {

@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
public Date getTimestamp() {
return (Date) timestamp.clone();
return timestamp;
}

public void setTimestamp(final @NotNull Date timestamp) {
Expand Down
8 changes: 2 additions & 6 deletions sentry/src/main/java/io/sentry/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ public boolean isTerminated() {

@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
public @Nullable Date getStarted() {
if (started == null) {
return null;
}
return (Date) started.clone();
return started;
}

public @Nullable String getDistinctId() {
Expand Down Expand Up @@ -193,8 +190,7 @@ public int errorCount() {

@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
public @Nullable Date getTimestamp() {
final Date timestampRef = timestamp;
return timestampRef != null ? (Date) timestampRef.clone() : null;
return timestamp;
}

/** Ends a session and update its values */
Expand Down
3 changes: 1 addition & 2 deletions sentry/src/main/java/io/sentry/protocol/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public void setAppIdentifier(final @Nullable String appIdentifier) {

@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
public @Nullable Date getAppStartTime() {
final Date appStartTimeRef = appStartTime;
return appStartTimeRef != null ? (Date) appStartTimeRef.clone() : null;
return appStartTime;
}

public void setAppStartTime(final @Nullable Date appStartTime) {
Expand Down
3 changes: 1 addition & 2 deletions sentry/src/main/java/io/sentry/protocol/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,7 @@ public void setScreenDpi(final @Nullable Integer screenDpi) {

@SuppressWarnings({"JdkObsolete", "JavaUtilDate"})
public @Nullable Date getBootTime() {
final Date bootTimeRef = bootTime;
return bootTimeRef != null ? (Date) bootTimeRef.clone() : null;
return bootTime;
}

public void setBootTime(final @Nullable Date bootTime) {
Expand Down
5 changes: 3 additions & 2 deletions sentry/src/test/java/io/sentry/protocol/AppTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNotSame
import kotlin.test.assertSame

class AppTest {
@Test
fun `copying app wont have the same references`() {
fun `copying app keeps date reference and copies collections`() {
val app = App()
app.appBuild = "app build"
app.appIdentifier = "app identifier"
Expand All @@ -28,7 +29,7 @@ class AppTest {

assertNotNull(clone)
assertNotSame(app, clone)
assertNotSame(app.appStartTime, clone.appStartTime)
assertSame(app.appStartTime, clone.appStartTime)
assertNotSame(app.permissions, clone.permissions)
assertNotSame(app.viewNames, clone.viewNames)

Expand Down
5 changes: 3 additions & 2 deletions sentry/src/test/java/io/sentry/protocol/DeviceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNotSame
import kotlin.test.assertSame

class DeviceTest {

@Test
fun `copying device wont have the same references`() {
fun `copying device keeps date reference and copies other mutable references`() {
val device = Device()
device.archs = arrayOf("archs1", "archs2")
device.bootTime = Date()
Expand All @@ -23,7 +24,7 @@ class DeviceTest {
assertNotNull(clone)
assertNotSame(device, clone)
assertNotSame(device.archs, clone.archs)
assertNotSame(device.bootTime, clone.bootTime)
assertSame(device.bootTime, clone.bootTime)
assertNotSame(device.timezone, clone.timezone)
assertNotSame(device.unknown, clone.unknown)
}
Expand Down
Loading