Skip to content

Commit 40c9b1e

Browse files
runningcodeclaude
andauthored
ref(android): Fix Error Prone warnings in sentry-android-core (#6499)
* ref(android): Fix Error Prone warnings in sentry-android-core Error Prone never ran on sentry-android-core. Enabling it reports 59 warnings outside Javadoc, which fail the build under -Werror. - Suppress FutureReturnValueIgnored, JavaUtilDate, and ReferenceEquality where identity is intended, as the sentry module does. - Keep the AnrProfilingIntegration updater a field, since removeCallbacks needs the instance that was posted, and suppress UnnecessaryLambda there. - Read the ANR thread dump and the app start profiling config as UTF-8, Android's default charset. - Remove unused fields and parameters, add missing @OverRide, make long-to-double conversions explicit, and narrow members that are effectively private or protected in a final class. - Explain the two catch blocks that ignore their exception. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ref(android): Fix the Error Prone warnings only main has - ANRWatchDog.monotonicTicker is never read (#6041), since the ticker lambda captures the constructor parameter. Remove the field and keep the parameter. - ActivityFramesTracker.lock is protected in a final class; make it package-private. - LifecycleWatcher reads the session start Date to seed the session window; suppress JavaUtilDate there, as the other Date uses are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ref(android): Keep the default charset reads as they were Android's default charset is always UTF-8, so DefaultCharset is disabled for the Android modules in #6493 instead of being fixed here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ref(android): Drop the UnnecessaryLambda suppressions #6493 disables UnnecessaryLambda for the Android modules, so the suppressions on the ANRWatchDog and AnrProfilingIntegration fields are redundant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ref(android): Drop the updater field comment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(android): Make the local-class method comment a plain comment Error Prone's NotJavadoc flags Javadoc on methods of local classes, which #6537 added in AndroidConnectionStatusProvider. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1c8f695 commit 40c9b1e

38 files changed

Lines changed: 59 additions & 31 deletions

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ final class ANRWatchDog extends Thread {
4949
private final boolean reportInDebug;
5050
private final ANRListener anrListener;
5151
private final MainLooperHandler uiHandler;
52-
private final MonotonicTicker monotonicTicker;
5352

5453
/** the interval in which we check if there's an ANR, in ms */
5554
private long pollingIntervalMs;
@@ -65,7 +64,6 @@ final class ANRWatchDog extends Thread {
6564
private final @NotNull Context context;
6665
private final @Nullable IDebugManager debugManager;
6766

68-
@SuppressWarnings("UnnecessaryLambda")
6967
private final Runnable ticker;
7068

7169
static @NotNull ANRWatchDog create(
@@ -97,7 +95,6 @@ final class ANRWatchDog extends Thread {
9795

9896
super("|ANR-WatchDog|");
9997

100-
this.monotonicTicker = monotonicTicker;
10198
this.timeoutIntervalMillis = timeoutIntervalMillis;
10299
this.pollingIntervalMs = pollingIntervalMillis;
103100
this.reportInDebug = reportInDebug;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class ActivityFramesTracker {
4040
new WeakHashMap<>();
4141

4242
private final @NotNull MainLooperHandler handler;
43-
protected @NotNull AutoClosableReentrantLock lock = new AutoClosableReentrantLock();
43+
@NotNull AutoClosableReentrantLock lock = new AutoClosableReentrantLock();
4444

4545
private final @NotNull LazyEvaluator<Boolean> androidXAvailable;
4646

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ void applyScope(final @NotNull IScope scope, final @NotNull ITransaction transac
496496
}
497497

498498
@VisibleForTesting
499+
@SuppressWarnings("ReferenceEquality")
499500
void clearScope(final @NotNull IScope scope, final @NotNull ITransaction transaction) {
500501
scope.withTransaction(
501502
scopeTransaction -> {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ private void stop(final boolean restartProfiler) {
335335
}
336336
}
337337

338+
@Override
338339
public void reevaluateSampling() {
339340
shouldSample = true;
340341
}
@@ -373,6 +374,7 @@ public void close(final boolean isTerminating) {
373374
return ProfileRecordingState.UNKNOWN;
374375
}
375376

377+
@SuppressWarnings("FutureReturnValueIgnored")
376378
private void sendChunks(final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
377379
try {
378380
options

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public void log(
2727
final @NotNull String message,
2828
final @Nullable Object... args) {
2929
if (args == null || args.length == 0) {
30-
Log.println(toLogcatLevel(level), tag, message);
30+
Log.println(Log.ASSERT, tag, message);
3131
} else {
32-
Log.println(toLogcatLevel(level), tag, String.format(message, args));
32+
Log.println(Log.ASSERT, tag, String.format(message, args));
3333
}
3434
}
3535

@@ -59,8 +59,4 @@ public void log(
5959
public boolean isEnabled(@Nullable SentryLevel level) {
6060
return true;
6161
}
62-
63-
private int toLogcatLevel(final @NotNull SentryLevel sentryLevel) {
64-
return Log.ASSERT;
65-
}
6662
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public void onForeground() {
2323
}
2424

2525
@Override
26+
@SuppressWarnings("FutureReturnValueIgnored")
2627
public void onBackground() {
2728
if (!hasAcceptedItem) {
2829
return;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public void onForeground() {
2323
}
2424

2525
@Override
26+
@SuppressWarnings("FutureReturnValueIgnored")
2627
public void onBackground() {
2728
if (!hasAcceptedItem) {
2829
return;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static void installDefaultIntegrations(
502502
options.setReplayController(replay);
503503
}
504504
if (isDistributionAvailable) {
505-
final DistributionIntegration distribution = new DistributionIntegration((context));
505+
final DistributionIntegration distribution = new DistributionIntegration(context);
506506
options.setDistributionController(distribution);
507507
options.addIntegration(distribution);
508508
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ public AnrIntegration(final @NotNull Context context) {
4747

4848
private @Nullable SentryOptions options;
4949

50-
protected static final @NotNull AutoClosableReentrantLock watchDogLock =
51-
new AutoClosableReentrantLock();
50+
static final @NotNull AutoClosableReentrantLock watchDogLock = new AutoClosableReentrantLock();
5251

5352
@Override
5453
public final void register(final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
5554
this.options = Objects.requireNonNull(options, "SentryOptions is required");
5655
register(scopes, (SentryAndroidOptions) options);
5756
}
5857

58+
@SuppressWarnings("FutureReturnValueIgnored")
5959
private void register(
6060
final @NotNull IScopes scopes, final @NotNull SentryAndroidOptions options) {
6161
options

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public AnrV2Integration(final @NotNull Context context) {
6464

6565
@SuppressLint("NewApi") // we do the check in the AnrIntegrationFactory
6666
@Override
67+
@SuppressWarnings("FutureReturnValueIgnored")
6768
public void register(@NotNull IScopes scopes, @NotNull SentryOptions options) {
6869
this.options =
6970
Objects.requireNonNull(

0 commit comments

Comments
 (0)