[Android] Fix NullPointerExceptions in beta logs

Nicolas Pomepuy git at videolan.org
Thu Oct 28 05:17:33 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Oct 28 07:12:15 2021 +0200| [f2aef14a46b650191b1d3c76eb40d621eb6fb4e7] | committer: Nicolas Pomepuy

Fix NullPointerExceptions in beta logs

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

 .../src/org/videolan/vlc/media/PlaylistManager.kt  | 24 +++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index b4dc064b5..ce8d5291c 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -106,7 +106,13 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
     fun loadLocations(mediaPathList: List<String>, position: Int) {
         if (BuildConfig.BETA) {
             Log.d(TAG, "loadLocations with values: ", Exception("Call stack"))
-            mediaPathList.forEach { Log.d(TAG, "Media location: $it") }
+            mediaPathList.forEach {
+                try {
+                    Log.d(TAG, "Media location: $it")
+                } catch (e: NullPointerException) {
+                    Log.d(TAG, "Media crash", e)
+                }
+            }
         }
         launch {
             val mediaList = ArrayList<MediaWrapper>()
@@ -141,7 +147,13 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         videoBackground = false
         if (BuildConfig.BETA) {
             Log.d(TAG, "load with values: ", Exception("Call stack"))
-            list.forEach { Log.d(TAG, "Media location: ${it.uri}") }
+            list.forEach {
+                try {
+                    Log.d(TAG, "Media location: ${it.uri}")
+                } catch (e: NullPointerException) {
+                    Log.d(TAG, "Media crash", e)
+                }
+            }
         }
         mediaList.replaceWith(list)
         if (!hasMedia()) {
@@ -782,7 +794,13 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
         val list = withContext(Dispatchers.IO) { list.updateWithMLMeta() }
         mediaList.removeEventListener(this)
         for (media in list) mediaList.add(media)
-        if (BuildConfig.BETA) list.forEach { Log.d(TAG, "Media location: ${it.uri}") }
+        if (BuildConfig.BETA) list.forEach {
+            try {
+                Log.d(TAG, "Media location: ${it.uri}")
+            } catch (e: NullPointerException) {
+                Log.d(TAG, "Media crash", e)
+            }
+        }
         mediaList.addEventListener(this)
         addUpdateActor.offer(Unit)
     }



More information about the Android mailing list