diff --git a/LauncherCore/src/main/java11/pro/gravit/utils/Downloader.java b/LauncherCore/src/main/java11/pro/gravit/utils/Downloader.java index 3ca5dcde..71dc6c4e 100644 --- a/LauncherCore/src/main/java11/pro/gravit/utils/Downloader.java +++ b/LauncherCore/src/main/java11/pro/gravit/utils/Downloader.java @@ -130,11 +130,12 @@ protected DownloadTask sendAsync(AsyncDownloader.SizedFile file, URI baseUri, Pa ProgressTrackingBodyHandler bodyHandler = makeBodyHandler(targetDir.resolve(file.filePath), callback); CompletableFuture> future = client.sendAsync(makeHttpRequest(baseUri, file.urlPath), bodyHandler); AtomicReference task = new AtomicReference<>(null); - task.set(new DownloadTask(bodyHandler, future.thenApply((e) -> { - tasks.remove(task.get()); - return e; - }))); + task.set(new DownloadTask(bodyHandler, null /* fix NPE (future already completed) */)); tasks.add(task.get()); + task.get().completableFuture = future.thenApply((e) -> { + tasks.remove(task.get()); + return e; + }); return task.get(); } @@ -168,7 +169,7 @@ private static class ConsumerObject { public static class DownloadTask { public final ProgressTrackingBodyHandler bodyHandler; - public final CompletableFuture> completableFuture; + public CompletableFuture> completableFuture; public DownloadTask(ProgressTrackingBodyHandler bodyHandler, CompletableFuture> completableFuture) { this.bodyHandler = bodyHandler;