[Android] Prevent NPE in notification generation

Geoffrey Métais git at videolan.org
Fri Dec 29 16:37:49 CET 2017


vlc-android | branch: 2.5.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 29 16:36:17 2017 +0100| [e41b23d63bf07c77e2e643493544948f8902e82c] | committer: Geoffrey Métais

Prevent NPE in notification generation

(cherry picked from commit 71c54fe25579686729331d05c9792d1047e265e5)

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

 vlc-android/src/org/videolan/vlc/util/Util.java | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index f1d491d9a..f2176cf04 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -171,10 +171,12 @@ public class Util {
 
     @NonNull
     public static String getMediaDescription(String artist, String album) {
-        StringBuilder contentBuilder = new StringBuilder(artist);
-        if (contentBuilder.length() > 0 && !TextUtils.isEmpty(album))
-            contentBuilder.append(" - ");
-        contentBuilder.append(album);
+        boolean hasArtist = !TextUtils.isEmpty(artist);
+        boolean hasAlbum = !TextUtils.isEmpty(album);
+        if (!hasAlbum && !hasArtist) return "";
+        StringBuilder contentBuilder = new StringBuilder(hasArtist ? artist : "");
+        if (hasArtist && hasAlbum) contentBuilder.append(" - ");
+        if (hasAlbum) contentBuilder.append(album);
         return contentBuilder.toString();
     }
 



More information about the Android mailing list