smanikandan14 / ThinDownloadManager

To download files and to avoid using DOWNLOAD_WITHOUT_NOTIFICATION permission if you are using Android's DownloadManager in your apps.
Apache License 2.0
783 stars 185 forks source link

NullPointerException at DownloadDispatcher.transferData #54

Closed CloudedDragon closed 8 years ago

CloudedDragon commented 8 years ago

03-06 03:51:24.442 15594-15754/? E/AndroidRuntime: FATAL EXCEPTION: Thread-61117 java.lang.NullPointerException at com.thin.downloadmanager.DownloadDispatcher.writeDataToDestination(DownloadDispatcher.java:315) at com.thin.downloadmanager.DownloadDispatcher.transferData(DownloadDispatcher.java:295) at com.thin.downloadmanager.DownloadDispatcher.transferData(DownloadDispatcher.java:238) at com.thin.downloadmanager.DownloadDispatcher.executeDownload(DownloadDispatcher.java:142) at com.thin.downloadmanager.DownloadDispatcher.run(DownloadDispatcher.java:81)

CloudedDragon commented 8 years ago

My device is Android 4.1.1 get NullPointerException , but when I use Android 4.4 device, and it work fine

dependencies {

compile 'com.mani:ThinDownloadManager:1.2.1'

}

BenOien commented 8 years ago

I ran into this too. I have a fix, and will create a pull request shortly.

Edit: Pull Request

praveen2gemini commented 8 years ago

I have updated to 'com.mani:ThinDownloadManager:1.2.2'. Actually DownloadDispatcher is trying to write data on destination. But the destination file was not available in that location, while It was trying to write streamed data. My suggestion is destination should be validated before write data! @harinair - Can you please have a look on this issue ?

 java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[], int, int)' on a null object reference
                                                                             at com.thin.downloadmanager.DownloadDispatcher.writeDataToDestination(DownloadDispatcher.java:315)
                                                                             at com.thin.downloadmanager.DownloadDispatcher.transferData(DownloadDispatcher.java:295)
                                                                             at com.thin.downloadmanager.DownloadDispatcher.transferData(DownloadDispatcher.java:238)
                                                                             at com.thin.downloadmanager.DownloadDispatcher.executeDownload(DownloadDispatcher.java:142)
                                                                             at com.thin.downloadmanager.DownloadDispatcher.run(DownloadDispatcher.java:81)
BenOien commented 8 years ago

My pull request is still pending approval. It is a very simple solution. My fork has it applied to master. I am currently weighing the benefits of maintaining the fork in light of my likely work toward new features. No promises though.

harinair commented 8 years ago

@PrimeKang I could not see any pull requests against this repo? Did you submit one? I noticed that many PR take a lot of time to get approved.

smanikandan14 commented 8 years ago

@CloudedDragon @praveen2gemini Please update to the latest version 1.2.3 @PrimeKang Appreciate your findings.

praveen2gemini commented 8 years ago

@smanikandan14 Fix doesn't resolve our issue. Our Scenario is like this. We are deleting the created file path in a separate thread whenever the user cancels the download from UI and by this time the download manager is trying to write to the file which is already deleted. This leads to the Null pointer exception crash. Why we followed this approach is because ThinDownload manager sets the cancel flag to true and doesn't stop the download(Thread) immediately. Also it throws the cancelled error only after few seconds and we cannot delay the UI updation till we get the download cancelled message.

smanikandan14 commented 8 years ago

This case is handled now safely. DownloadManager.ERROR_FILE_ERROR will be given in the callback onDownloadFailed if the destination file is not found during download. Please try version 1.2.4

smanikandan14 commented 8 years ago

@praveen2gemini Closing this if there are no concerns.

praveen2gemini commented 8 years ago

@smanikandan14 It works! Thanks.

harinair commented 8 years ago

@praveen2gemini @smanikandan14 Thank you for taking care of this.