[Android] Fix unsafe uses of nullable receivers

Nicolas Pomepuy git at videolan.org
Mon Nov 14 09:54:16 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Nov  4 09:28:06 2022 +0100| [706fae0e3de5d90234a4d07c2bcec547416914df] | committer: Nicolas Pomepuy

Fix unsafe uses of nullable receivers

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

 application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt b/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
index f987a9f53..388867d66 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
@@ -194,7 +194,7 @@ object FileUtils {
         if (src.isDirectory) {
             val filesList = src.listFiles()
             dst.mkdirs()
-            for (file in filesList)
+            for (file in filesList ?: arrayOf())
                 ret = ret and copyFile(file, File(dst, file.name))
         } else if (src.isFile) {
             var inputStream: InputStream? = null
@@ -242,7 +242,7 @@ object FileUtils {
         //Delete from Android Medialib, for consistency with device MTP storing and other apps listing content:// media
         if (file.isDirectory) {
             deleted = true
-            for (child in file.listFiles()) deleted = deleted and deleteFile(child)
+            for (child in file.listFiles() ?: arrayOf()) deleted = deleted and deleteFile(child)
             if (deleted) deleted = deleted and file.delete()
         } else {
             val cr = AppContextProvider.appContext.contentResolver
@@ -276,7 +276,7 @@ object FileUtils {
                 return at Runnable
             val success: Boolean
             if (fileOrDirectory.isDirectory) {
-                for (child in fileOrDirectory.listFiles())
+                for (child in fileOrDirectory.listFiles() ?: arrayOf())
                     asyncRecursiveDelete(child, null)
                 success = fileOrDirectory.delete()
             } else {



More information about the Android mailing list