From 111d7616d0f8c74e3049eca6ab009e152140d1c4 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 23 Mar 2023 18:56:23 +0700 Subject: [PATCH] [FIX] NPE --- .../src/main/java11/pro/gravit/utils/Downloader.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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;