Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

目标存储路径是文件,而不是文件夹情况下的异常处理设计不太合理 #41

Closed
AzureFatty opened this issue Apr 24, 2018 · 2 comments
Labels
Milestone

Comments

@AzureFatty
Copy link

AzureFatty commented Apr 24, 2018

DownloadTask.java

try {
    ...
    if (file.exists() && file.isFile()) {
    // it have already provided file for it.
	throw new IllegalArgumentException("If you want filename from "
					+ "response please make sure you provide path is directory " + file.getPath());
    }
    ...
} finally {
    this.id = OkDownload.with().breakpointStore().findOrCreateId(this);
}

此处判断file.exists() && file.isFile()抛出IllegalArgumentException异常,
当此判断条件成立时,因为加了finally,所以代码还会执行
this.id = OkDownload.with().breakpointStore().findOrCreateId(this);
而此时会抛出

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xxx.sample.webdownloader, PID: 16251
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.liulishuo.okdownload.core.download.DownloadStrategy$FilenameHolder.get()' on a null object reference
        at com.liulishuo.okdownload.DownloadTask.getFilename(DownloadTask.java:230)
        at com.liulishuo.okdownload.core.breakpoint.KeyToIdMap.generateKey(KeyToIdMap.java:63)
        at com.liulishuo.okdownload.core.breakpoint.KeyToIdMap.get(KeyToIdMap.java:43)
        at com.liulishuo.okdownload.core.breakpoint.BreakpointStoreOnCache.findOrCreateId(BreakpointStoreOnCache.java:146)
        at com.liulishuo.okdownload.core.breakpoint.BreakpointStoreOnSQLite.findOrCreateId(BreakpointStoreOnSQLite.java:100)
        at com.liulishuo.okdownload.DownloadTask.<init>(DownloadTask.java:190)
        at com.liulishuo.okdownload.DownloadTask$Builder.build(DownloadTask.java:838)

从而掩盖了
throw new IllegalArgumentException("If you want filename from " + "response please make sure you provide path is directory " + file.getPath());
的异常信息。

导致追查问题时不方便。

@AzureFatty AzureFatty changed the title 异常处理不太合理 DownloadTask 路径是文件,而不是文件夹情况下的异常处理设计不太合理 Apr 24, 2018
@AzureFatty AzureFatty changed the title DownloadTask 路径是文件,而不是文件夹情况下的异常处理设计不太合理 目标存储路径是文件,而不是文件夹情况下的异常处理设计不太合理 Apr 24, 2018
@Jacksgong Jacksgong added the bug label Apr 24, 2018
@Jacksgong Jacksgong added this to the 1.0.2 milestone Apr 24, 2018
@Jacksgong
Copy link
Collaborator

感谢反馈。

@Jacksgong
Copy link
Collaborator

该问题已经在1.0.2-SNAPSHOT上修复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants