From 74d379a09c377320ccf569acc572f689433da2c2 Mon Sep 17 00:00:00 2001 From: Glavo Date: Mon, 5 Jan 2026 21:51:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20FetchTask=20=E6=9C=AA?= =?UTF-8?q?=E6=8D=95=E8=8E=B7=E9=83=A8=E5=88=86=E5=BC=82=E5=B8=B8=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#5144)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jackhuang/hmcl/task/FetchTask.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FetchTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FetchTask.java index 742c4fcb0..d5c26142c 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FetchTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FetchTask.java @@ -185,7 +185,7 @@ public abstract class FetchTask extends Task { } } - ArrayList exceptions = null; + ArrayList exceptions = null; // If loading the cache fails, the cache should not be loaded again. boolean useCachedResult = true; @@ -284,10 +284,12 @@ public abstract class FetchTask extends Task { contentLength, contentEncoding); return; + } catch (InterruptedException e) { + throw e; } catch (FileNotFoundException ex) { LOG.warning("Failed to download " + uri + ", not found" + (redirects == null ? "" : ", redirects: " + redirects), ex); throw toDownloadException(uri, ex, exceptions); // we will not try this URL again - } catch (IOException ex) { + } catch (Exception ex) { if (exceptions == null) exceptions = new ArrayList<>(); @@ -301,7 +303,7 @@ public abstract class FetchTask extends Task { } private void downloadNotHttp(URI uri) throws DownloadException, InterruptedException { - ArrayList exceptions = null; + ArrayList exceptions = null; for (int retryTime = 0; retryTime < retry; retryTime++) { if (isCancelled()) { throw new InterruptedException(); @@ -317,11 +319,13 @@ public abstract class FetchTask extends Task { conn.getContentLengthLong(), ContentEncoding.fromConnection(conn)); return; + } catch (InterruptedException e) { + throw e; } catch (FileNotFoundException ex) { LOG.warning("Failed to download " + uri + ", not found", ex); throw toDownloadException(uri, ex, exceptions); // we will not try this URL again - } catch (IOException ex) { + } catch (Exception ex) { if (exceptions == null) exceptions = new ArrayList<>(); @@ -333,7 +337,7 @@ public abstract class FetchTask extends Task { throw toDownloadException(uri, null, exceptions); } - private static DownloadException toDownloadException(URI uri, @Nullable IOException last, @Nullable ArrayList exceptions) { + private static DownloadException toDownloadException(URI uri, @Nullable Exception last, @Nullable ArrayList exceptions) { if (exceptions == null || exceptions.isEmpty()) { return new DownloadException(uri, last != null ? last @@ -342,7 +346,7 @@ public abstract class FetchTask extends Task { if (last == null) last = exceptions.remove(exceptions.size() - 1); - for (IOException e : exceptions) { + for (Exception e : exceptions) { last.addSuppressed(e); } return new DownloadException(uri, last);