[Android] Prevent NPE in notification generation

Geoffrey Métais git at videolan.org
Tue Jan 16 17:45:22 CET 2018


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

Prevent NPE in notification generation

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

 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 c8badb25b..ab7df1aaf 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -164,10 +164,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