Getting document info may crash in rare cases
gmk57 opened this issue · 3 comments
Stack trace:
java.lang.NullPointerException: Attempt to invoke interface method 'void android.database.Cursor.close()' on a null object reference
at com.commonsware.cwac.document.DocumentsContractApi1.queryForString(DocumentsContractApi1.java:58)
at com.commonsware.cwac.document.DocumentsContractApi1.getName(DocumentsContractApi1.java:31)
at com.commonsware.cwac.document.SingleLegacyDocumentFile.getName(SingleLegacyDocumentFile.java:55)
Steps to reproduce:
- Fire intent with ACTION_GET_CONTENT (example here) on emulator with API 21
- Choose any file from Gallery or Music app
In this case resolver.query() throws SecurityException if an app doesn't have READ_EXTERNAL_STORAGE permission (mentioned in comments to this question), so the cursor is null.
I suppose a simple null-check in finally
would be enough to fix it.
Thanks for a nice library! :)
Good point! I'll look to add null
checks to those finally
clauses. I'll try to work on it this weekend. Thanks!
OK, while this fix is not that bad to implement, this whole library needs a rewrite. It's still using the Support Library, for example. I'll work on that in the coming months.
Since I needed to make another change (finally moving to AndroidX!), I elected to tuck this fix in there. v0.5.0 should address this problem. Thanks for pointing it out!