lingochamp / okdownload

A Reliable, Flexible, Fast and Powerful download engine.
Apache License 2.0
5.19k stars 776 forks source link

NullPointerException at "compareIgnoreId(IdentifiedTask.java:40)" #398

Closed sametbars closed 4 years ago

sametbars commented 4 years ago

OkDownload Version

v1.0.7

Problem Describe

1- Download a file 2- Delete downloaded file 3- Try to download same url & filename and you get NPE

My implementation:

OkDownload.setSingletonInstance(new OkDownload.Builder(getAppContext()).downloadStrategy(new DownloadStrategy() {
            @Override
            public int determineBlockCount(@NonNull DownloadTask task, long totalLength) {
                try {
                    int count = Math.max(3, Math.round((int)(totalLength / 5242880)));
                    if (count > 6) {
                        count = 6;
                    }
                    return count;
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return 1;
            }
        }).build());

Log

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
2020-06-22 17:22:09.045 13128-13298 W/System.err: at com.liulishuo.okdownload.core.IdentifiedTask.compareIgnoreId(IdentifiedTask.java:40)
2020-06-22 17:22:09.045 13128-13298 W/System.err: at com.liulishuo.okdownload.core.breakpoint.BreakpointStoreOnCache.findOrCreateId(BreakpointStoreOnCache.java:183)
2020-06-22 17:22:09.045 13128-13298 W/System.err: at com.liulishuo.okdownload.core.breakpoint.BreakpointStoreOnSQLite.findOrCreateId(BreakpointStoreOnSQLite.java:116)
2020-06-22 17:22:09.045 13128-13298 W/System.err: at com.liulishuo.okdownload.DownloadTask.<init>(DownloadTask.java:197)
2020-06-22 17:22:09.045 13128-13298 W/System.err: at com.liulishuo.okdownload.DownloadTask$Builder.build(DownloadTask.java:916)
MBakhshi96 commented 3 years ago

@sametbars Did you find a solution for this problem? what was causing the NPE?

sametbars commented 1 year ago

@sametbars Did you find a solution for this problem? what was causing the NPE?

I wrapped the whole compareIgnoreId function in try-catch block and returned false in catch block.