[Android] Prevent NPE

Geoffrey Métais git at videolan.org
Wed Aug 30 16:49:49 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Aug 30 16:37:00 2017 +0200| [8ff454e25a7c94e25a07c1e82cb2a1ecbd79136c] | committer: Geoffrey Métais

Prevent NPE

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

 vlc-android/src/org/videolan/vlc/media/MediaUtils.java | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
index a66f1b3aa..c17ca788a 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaUtils.java
@@ -16,7 +16,6 @@ import org.videolan.vlc.PlaybackService;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.util.FileUtils;
-import org.videolan.vlc.util.Strings;
 import org.videolan.vlc.util.SubtitlesDownloader;
 import org.videolan.vlc.util.Util;
 
@@ -144,28 +143,28 @@ public class MediaUtils {
     }
 
     public static String getMediaArtist(Context ctx, MediaWrapper media) {
-        final String artist = media.getArtist();
+        final String artist = media != null ? media.getArtist() : null;
         return artist != null ? artist : getMediaString(ctx, R.string.unknown_artist);
     }
 
     public static String getMediaReferenceArtist(Context ctx, MediaWrapper media) {
-        final String artist = media.getReferenceArtist();
+        final String artist = media != null ? media.getReferenceArtist() : null;
         return artist != null ? artist : getMediaString(ctx, R.string.unknown_artist);
     }
 
     public static String getMediaAlbumArtist(Context ctx, MediaWrapper media) {
-        final String albumArtist = media.getAlbumArtist();
+        final String albumArtist = media != null ? media.getAlbumArtist() : null;
         return albumArtist != null ? albumArtist : getMediaString(ctx, R.string.unknown_artist);
     }
 
     public static String getMediaAlbum(Context ctx, MediaWrapper media) {
-        final String album = media.getAlbum();
+        final String album = media != null ? media.getAlbum() : null;
         return album != null ? album : getMediaString(ctx, R.string.unknown_album);
 
     }
 
     public static String getMediaGenre(Context ctx, MediaWrapper media) {
-        final String genre = media.getGenre();
+        final String genre = media != null ? media.getGenre() : null;
         return genre != null ? genre : getMediaString(ctx, R.string.unknown_genre);
     }
 



More information about the Android mailing list