[Android] Fix NullPointerException whe deleting files

Nicolas Pomepuy git at videolan.org
Tue Aug 27 13:01:41 CEST 2019


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

Fix NullPointerException whe deleting files

(cherry picked from commit 40579537bd7e222dbe393a764792744e3aa2ba0a)

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

 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