删除 CompletableFutureTask.resolveException (#4690)

This commit is contained in:
Glavo
2025-10-18 21:47:39 +08:00
committed by GitHub
parent 22f6bfd845
commit 16f6e89e45

View File

@@ -17,9 +17,10 @@
*/
package org.jackhuang.hmcl.task;
import org.jackhuang.hmcl.util.Lang;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
public abstract class CompletableFutureTask<T> extends Task<T> {
@@ -29,18 +30,11 @@ public abstract class CompletableFutureTask<T> extends Task<T> {
public abstract CompletableFuture<T> getFuture(TaskCompletableFuture executor);
protected static Throwable resolveException(Throwable e) {
if (e instanceof ExecutionException || e instanceof CompletionException)
return resolveException(e.getCause());
else
return e;
}
public static class CustomException extends RuntimeException {}
protected static CompletableFuture<Void> breakable(CompletableFuture<?> future) {
return future.thenApplyAsync(unused1 -> (Void) null).exceptionally(throwable -> {
if (resolveException(throwable) instanceof CustomException) return null;
if (Lang.resolveException(throwable) instanceof CustomException) return null;
else throw new CompletionException(throwable);
});
}