[Android] Fix NullPointerException whe deleting files

Nicolas Pomepuy git at videolan.org
Tue Aug 20 09:03:13 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Aug 20 07:03:31 2019 +0200| [40579537bd7e222dbe393a764792744e3aa2ba0a] | committer: Nicolas Pomepuy

Fix NullPointerException whe deleting files

> https://code.videolan.org/videolan/vlc-android/commit/40579537bd7e222dbe393a764792744e3aa2ba0a
---

 vlc-android/src/org/videolan/vlc/util/FileUtils.kt | 27 ++++++++++++----------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.kt b/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
index 41ec6c823..e24207c7f 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
@@ -323,19 +323,22 @@ object FileUtils {
 
     @WorkerThread
     fun findFile(uri: Uri): DocumentFile? {
-        val storage = getMediaStorage(uri)
-        val treePref = Settings.getInstance(VLCApplication.appContext).getString("tree_uri_" + storage!!, null)
-                ?: return null
-        val treeUri = Uri.parse(treePref)
-        var documentFile = DocumentFile.fromTreeUri(VLCApplication.appContext, treeUri)
-        val parts = uri.path.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
-        for (i in 3 until parts.size) {
-            if (documentFile != null)
-                documentFile = documentFile.findFile(parts[i])
-            else
-                return null
+        uri.path?.let { path ->
+            val storage = getMediaStorage(uri)
+            val treePref = Settings.getInstance(VLCApplication.appContext).getString("tree_uri_" + storage!!, null)
+                    ?: return null
+            val treeUri = Uri.parse(treePref)
+            var documentFile = DocumentFile.fromTreeUri(VLCApplication.appContext, treeUri)
+            val parts = path.split("/".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
+            for (i in 3 until parts.size) {
+                if (documentFile != null)
+                    documentFile = documentFile.findFile(parts[i])
+                else
+                    return null
+            }
+            return documentFile
         }
-        return documentFile
+        return null
 
     }
 



More information about the Android mailing list