修复 FetchTask 未捕获部分异常的问题 (#5144)
This commit is contained in:
@@ -185,7 +185,7 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<IOException> exceptions = null;
|
ArrayList<Exception> exceptions = null;
|
||||||
|
|
||||||
// If loading the cache fails, the cache should not be loaded again.
|
// If loading the cache fails, the cache should not be loaded again.
|
||||||
boolean useCachedResult = true;
|
boolean useCachedResult = true;
|
||||||
@@ -284,10 +284,12 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
contentLength,
|
contentLength,
|
||||||
contentEncoding);
|
contentEncoding);
|
||||||
return;
|
return;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw e;
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
LOG.warning("Failed to download " + uri + ", not found" + (redirects == null ? "" : ", redirects: " + redirects), 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
|
throw toDownloadException(uri, ex, exceptions); // we will not try this URL again
|
||||||
} catch (IOException ex) {
|
} catch (Exception ex) {
|
||||||
if (exceptions == null)
|
if (exceptions == null)
|
||||||
exceptions = new ArrayList<>();
|
exceptions = new ArrayList<>();
|
||||||
|
|
||||||
@@ -301,7 +303,7 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void downloadNotHttp(URI uri) throws DownloadException, InterruptedException {
|
private void downloadNotHttp(URI uri) throws DownloadException, InterruptedException {
|
||||||
ArrayList<IOException> exceptions = null;
|
ArrayList<Exception> exceptions = null;
|
||||||
for (int retryTime = 0; retryTime < retry; retryTime++) {
|
for (int retryTime = 0; retryTime < retry; retryTime++) {
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
throw new InterruptedException();
|
throw new InterruptedException();
|
||||||
@@ -317,11 +319,13 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
conn.getContentLengthLong(),
|
conn.getContentLengthLong(),
|
||||||
ContentEncoding.fromConnection(conn));
|
ContentEncoding.fromConnection(conn));
|
||||||
return;
|
return;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw e;
|
||||||
} catch (FileNotFoundException ex) {
|
} catch (FileNotFoundException ex) {
|
||||||
LOG.warning("Failed to download " + uri + ", not found", ex);
|
LOG.warning("Failed to download " + uri + ", not found", ex);
|
||||||
|
|
||||||
throw toDownloadException(uri, ex, exceptions); // we will not try this URL again
|
throw toDownloadException(uri, ex, exceptions); // we will not try this URL again
|
||||||
} catch (IOException ex) {
|
} catch (Exception ex) {
|
||||||
if (exceptions == null)
|
if (exceptions == null)
|
||||||
exceptions = new ArrayList<>();
|
exceptions = new ArrayList<>();
|
||||||
|
|
||||||
@@ -333,7 +337,7 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
throw toDownloadException(uri, null, exceptions);
|
throw toDownloadException(uri, null, exceptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DownloadException toDownloadException(URI uri, @Nullable IOException last, @Nullable ArrayList<IOException> exceptions) {
|
private static DownloadException toDownloadException(URI uri, @Nullable Exception last, @Nullable ArrayList<Exception> exceptions) {
|
||||||
if (exceptions == null || exceptions.isEmpty()) {
|
if (exceptions == null || exceptions.isEmpty()) {
|
||||||
return new DownloadException(uri, last != null
|
return new DownloadException(uri, last != null
|
||||||
? last
|
? last
|
||||||
@@ -342,7 +346,7 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
if (last == null)
|
if (last == null)
|
||||||
last = exceptions.remove(exceptions.size() - 1);
|
last = exceptions.remove(exceptions.size() - 1);
|
||||||
|
|
||||||
for (IOException e : exceptions) {
|
for (Exception e : exceptions) {
|
||||||
last.addSuppressed(e);
|
last.addSuppressed(e);
|
||||||
}
|
}
|
||||||
return new DownloadException(uri, last);
|
return new DownloadException(uri, last);
|
||||||
|
|||||||
Reference in New Issue
Block a user