[Android] Prevent a NullPointerException while parsing the play queue

Nicolas Pomepuy git at videolan.org
Thu Sep 23 11:01:20 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Sep 23 08:42:04 2021 +0200| [685064f5e908017d199ca98480da924d079d8b55] | committer: Nicolas Pomepuy

Prevent a NullPointerException while parsing the play queue

I can't understand why it's happening and the stacktrace in the Play
Store is not useful. As not having the artworkUri for one media is
not that critical, it's probably better to workaround this crash
and live with a missing cover.

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

 .../vlc-android/src/org/videolan/vlc/PlaybackService.kt     | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index ea5ce646d..a91f3eee1 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1179,10 +1179,15 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
         artworkMap = HashMap<String, Uri>().also {
             val artworkToUriCache = HashMap<String, Uri>()
             for (media in playlistManager.getMediaList()) {
-                if (!media.artworkMrl.isNullOrEmpty() && isPathValid(media.artworkMrl)) {
-                    val artworkUri = artworkToUriCache.getOrPut(media.artworkMrl, { ArtworkProvider.buildMediaUri(media) } )
-                    val key = MediaSessionBrowser.generateMediaId(media)
-                    it[key] = artworkUri
+                try {
+                    val artworkMrl = media.artworkMrl
+                    if (!artworkMrl.isNullOrEmpty() && isPathValid(artworkMrl)) {
+                        val artworkUri = artworkToUriCache.getOrPut(artworkMrl, { ArtworkProvider.buildMediaUri(media) } )
+                        val key = MediaSessionBrowser.generateMediaId(media)
+                        it[key] = artworkUri
+                    }
+                } catch (e: java.lang.NullPointerException) {
+                    Log.e("PlaybackService", "Caught NullPointerException", e)
                 }
             }
             artworkToUriCache.clear()



More information about the Android mailing list