lingochamp / FileDownloader

Multitask、MultiThread(MultiConnection)、Breakpoint-resume、High-concurrency、Simple to use、Single/NotSingle-process
Apache License 2.0
11.04k stars 2.2k forks source link

多任务下载时,取消下载会报空指针 #1181

Open hellozengms opened 5 years ago

hellozengms commented 5 years ago

java.lang.NullPointerException

解析原始 1 java.io.File.(File.java:262) 2 com.liulishuo.filedownloader.download.DownloadStatusCallback.void renameTempFile()(DownloadStatusCallback.java:294) 3 com.liulishuo.filedownloader.download.DownloadStatusCallback.void handleCompleted()(DownloadStatusCallback.java:381) 4 com.liulishuo.filedownloader.download.DownloadStatusCallback.void onCompletedDirectly()(DownloadStatusCallback.java:197) 5 com.liulishuo.filedownloader.download.DownloadLaunchRunnable.void run()(DownloadLaunchRunnable.java:336) 6 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 7 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 8 java.lang.Thread.run(Thread.java:761)

rantianhua commented 5 years ago

你有没有给你的每个任务设置 path ?或者 filename ? 直接出示一下你如果初始化你的多个 Task 的?

hellozengms commented 5 years ago
final List<BaseDownloadTask> tasks = new ArrayList<>();
    FileDownloadQueueSet queueSet = new FileDownloadQueueSet(new FileDownloadListener() {
        @Override
        protected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {
        }

        @Override
        protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {
        }

        @Override
        protected void completed(BaseDownloadTask task) {

        }

        @Override
        protected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) {

        }

        @Override
        protected void error(BaseDownloadTask task, Throwable e) {

        }

        @Override
        protected void warn(BaseDownloadTask task) {

        }
    });
    for (String url : urls) {
        tasks.add(FileDownloader.getImpl().create(url)
                .setTag(url).setPath(dirPath, true));
    }
    queueSet.disableCallbackProgressTimes();
    queueSet.setSyncCallback(isSync);
    queueSet.setAutoRetryTimes(3);
    queueSet.setForceReDownload(true);
    // 并行下载
    queueSet.downloadTogether(tasks);
    queueSet.start();
rantianhua commented 5 years ago

你的 dirPath 有没有可能为空?

KennethYo commented 1 year ago

这个问题,我能复现的,使用一个无法访问会返回404的链接,传递路径使用setPath(dirPath, true),就会出现空指针异常