Skip to content

Commit fb7e32b

Browse files
committed
ref(time): Deprecate DateUtils.getCurrentDateTime (JAVA-571)
It reads the wall clock into a java.util.Date at millisecond resolution. SentryDateProvider already owns wall time, is configurable, stubbable in tests and resolves finer, so there is no reason for new code to reach for the static. The class itself is not deprecated: its other fourteen statics are pure conversion and formatting helpers with no clock in them. Every caller keeps working and gets a suppression, because -Xlint:all -Werror turns the warning into a build failure. Each suppression carries a TODO [MAJOR] naming the replacement, since a suppressed warning is no longer a checklist entry — and nearly all of these callers are frozen until the next major anyway, as they stamp serialized timestamps.
1 parent 77eb8c9 commit fb7e32b

10 files changed

Lines changed: 33 additions & 3 deletions

File tree

‎sentry-android-core/src/main/java/io/sentry/android/core/AndroidProfiler.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public AndroidProfiler(
117117
}
118118

119119
@SuppressLint("NewApi")
120+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
121+
@SuppressWarnings("deprecation")
120122
public @Nullable ProfileStartData start() {
121123
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
122124
// intervalUs is 0 only if there was a problem in the init

‎sentry-android-core/src/main/java/io/sentry/android/core/AndroidTransactionProfiler.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public AndroidTransactionProfiler(
8989
() -> executorService);
9090
}
9191

92+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
93+
@SuppressWarnings("deprecation")
9294
public AndroidTransactionProfiler(
9395
final @NotNull Context context,
9496
final @NotNull BuildInfoProvider buildInfoProvider,

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public Breadcrumb(final long timestamp) {
9797
* @param options - the sentry options
9898
* @return the breadcrumb
9999
*/
100-
@SuppressWarnings("unchecked")
100+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
101+
@SuppressWarnings({"unchecked", "deprecation"})
101102
public static Breadcrumb fromMap(
102103
@NotNull Map<String, Object> map, @NotNull SentryOptions options) {
103104

@@ -882,7 +883,8 @@ public void serialize(final @NotNull ObjectWriter writer, final @NotNull ILogger
882883
}
883884

884885
public static final class Deserializer implements JsonDeserializer<Breadcrumb> {
885-
@SuppressWarnings("unchecked")
886+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
887+
@SuppressWarnings({"unchecked", "deprecation"})
886888
@Override
887889
public @NotNull Breadcrumb deserialize(@NotNull ObjectReader reader, @NotNull ILogger logger)
888890
throws Exception {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ private DateUtils() {}
1919
* Get the current Date (UTC)
2020
*
2121
* @return the UTC Date
22+
* @deprecated use {@code options.getDateProvider().now()}, which is configurable and resolves
23+
* finer than a millisecond.
2224
*/
23-
@SuppressWarnings("JavaUtilDate")
25+
@Deprecated
26+
// not @InlineMe: the replacement is options.getDateProvider().now(), not this method's body
27+
@SuppressWarnings({"JavaUtilDate", "InlineMeSuggester"})
2428
public static @NotNull Date getCurrentDateTime() {
2529
return new Date();
2630
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ private ProfilingTraceData() {
7575
this(new File("dummy"), NoOpTransaction.getInstance());
7676
}
7777

78+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
79+
@SuppressWarnings("deprecation")
7880
public ProfilingTraceData(
7981
final @NotNull File traceFile, final @NotNull ITransaction transaction) {
8082
this(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public SentryEvent(final @Nullable Throwable throwable) {
103103
this.throwable = throwable;
104104
}
105105

106+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
107+
@SuppressWarnings("deprecation")
106108
public SentryEvent() {
107109
this(new SentryId(), DateUtils.getCurrentDateTime());
108110
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public static final class Deserializer implements JsonDeserializer<ReplayType> {
5252
private @Nullable List<String> segmentNames;
5353
private @Nullable Map<String, Object> unknown;
5454

55+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
56+
@SuppressWarnings("deprecation")
5557
public SentryReplayEvent() {
5658
super();
5759
this.replayId = new SentryId();

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public Session(
112112
this.abnormalMechanism = abnormalMechanism;
113113
}
114114

115+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
116+
@SuppressWarnings("deprecation")
115117
public Session(
116118
@Nullable String distinctId,
117119
final @Nullable User user,
@@ -221,6 +223,8 @@ public boolean hasNonTerminatingUnhandledError() {
221223
*
222224
* @return whether the session was updated, i.e. false if it had already reached a terminal state
223225
*/
226+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
227+
@SuppressWarnings("deprecation")
224228
@ApiStatus.Internal
225229
public boolean recordNonTerminatingUnhandledError() {
226230
try (final @NotNull ISentryLifecycleToken ignored = sessionLock.acquire()) {
@@ -242,6 +246,8 @@ public boolean recordNonTerminatingUnhandledError() {
242246
}
243247

244248
/** Ends a session and update its values */
249+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
250+
@SuppressWarnings("deprecation")
245251
public void end() {
246252
end(DateUtils.getCurrentDateTime());
247253
}
@@ -251,6 +257,8 @@ public void end() {
251257
*
252258
* @param timestamp the timestamp or null
253259
*/
260+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
261+
@SuppressWarnings("deprecation")
254262
public void end(final @Nullable Date timestamp) {
255263
try (final @NotNull ISentryLifecycleToken ignored = sessionLock.acquire()) {
256264
init = null;
@@ -301,6 +309,8 @@ public boolean update(
301309
* @param abnormalMechanism the mechanism which caused the session to be abnormal
302310
* @return if the session has been updated
303311
*/
312+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
313+
@SuppressWarnings("deprecation")
304314
public boolean update(
305315
final @Nullable State status,
306316
final @Nullable String userAgent,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ private void tryEndPreviousSession(final @NotNull Hint hint) {
279279
}
280280
}
281281

282+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
283+
@SuppressWarnings("deprecation")
282284
private void writeCrashMarkerFile() {
283285
final File crashMarkerFile = new File(options.getCacheDirPath(), CRASH_MARKER_FILE);
284286
try (final OutputStream outputStream = new FileOutputStream(crashMarkerFile)) {

‎sentry/src/main/java/io/sentry/clientreport/ClientReportRecorder.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ private long itemCountFromHeader(final @NotNull SentryEnvelopeItem envelopeItem)
164164
return itemCount != null ? itemCount : 1L;
165165
}
166166

167+
// TODO [MAJOR]: replace DateUtils.getCurrentDateTime() with options.getDateProvider().now()
168+
@SuppressWarnings("deprecation")
167169
@Nullable
168170
ClientReport resetCountsAndGenerateClientReport() {
169171
final Date currentDate = DateUtils.getCurrentDateTime();

0 commit comments

Comments
 (0)