Skip to content

Commit d3b97eb

Browse files
runningcodeclaude
andcommitted
refactor(sentry): Use custom CompletedFuture for API 21+ compatibility (EME-413)
Replace CompletableFuture.completedFuture() with a custom CompletedFuture implementation in NoOpDistributionApi to maintain Android API 21+ compatibility. CompletableFuture was only added in Android API 24. The new CompletedFuture follows the same pattern as existing CancelledFuture implementations in the codebase and returns an immediately completed Future with a result. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f0ba78d commit d3b97eb

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

sentry/src/main/java/io/sentry/NoOpDistributionApi.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.sentry;
22

3-
import java.util.concurrent.CompletableFuture;
3+
import java.util.concurrent.ExecutionException;
44
import java.util.concurrent.Future;
5+
import java.util.concurrent.TimeUnit;
6+
import java.util.concurrent.TimeoutException;
57
import org.jetbrains.annotations.ApiStatus;
68
import org.jetbrains.annotations.NotNull;
79

@@ -24,7 +26,7 @@ public static NoOpDistributionApi getInstance() {
2426

2527
@Override
2628
public @NotNull Future<UpdateStatus> checkForUpdate() {
27-
return CompletableFuture.completedFuture(UpdateStatus.UpToDate.getInstance());
29+
return new CompletedFuture<>(UpdateStatus.UpToDate.getInstance());
2830
}
2931

3032
@Override
@@ -36,4 +38,42 @@ public void downloadUpdate(@NotNull UpdateInfo info) {
3638
public boolean isEnabled() {
3739
return false;
3840
}
41+
42+
/**
43+
* A Future implementation that is already completed with a result. This is used instead of
44+
* CompletableFuture.completedFuture() to maintain compatibility with Android API 21+.
45+
*/
46+
private static final class CompletedFuture<T> implements Future<T> {
47+
private final T result;
48+
49+
CompletedFuture(T result) {
50+
this.result = result;
51+
}
52+
53+
@Override
54+
public boolean cancel(final boolean mayInterruptIfRunning) {
55+
return false;
56+
}
57+
58+
@Override
59+
public boolean isCancelled() {
60+
return false;
61+
}
62+
63+
@Override
64+
public boolean isDone() {
65+
return true;
66+
}
67+
68+
@Override
69+
public T get() throws ExecutionException {
70+
return result;
71+
}
72+
73+
@Override
74+
public T get(final long timeout, final @NotNull TimeUnit unit)
75+
throws ExecutionException, TimeoutException {
76+
return result;
77+
}
78+
}
3979
}

0 commit comments

Comments
 (0)