Skip to content

Commit d60461b

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 23a841c commit d60461b

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,11 +26,49 @@ 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
3133
public void downloadUpdate(@NotNull UpdateInfo info) {
3234
// No-op implementation - do nothing
3335
}
36+
37+
/**
38+
* A Future implementation that is already completed with a result. This is used instead of
39+
* CompletableFuture.completedFuture() to maintain compatibility with Android API 21+.
40+
*/
41+
private static final class CompletedFuture<T> implements Future<T> {
42+
private final T result;
43+
44+
CompletedFuture(T result) {
45+
this.result = result;
46+
}
47+
48+
@Override
49+
public boolean cancel(final boolean mayInterruptIfRunning) {
50+
return false;
51+
}
52+
53+
@Override
54+
public boolean isCancelled() {
55+
return false;
56+
}
57+
58+
@Override
59+
public boolean isDone() {
60+
return true;
61+
}
62+
63+
@Override
64+
public T get() throws ExecutionException {
65+
return result;
66+
}
67+
68+
@Override
69+
public T get(final long timeout, final @NotNull TimeUnit unit)
70+
throws ExecutionException, TimeoutException {
71+
return result;
72+
}
73+
}
3474
}

0 commit comments

Comments
 (0)