[Android] Avoid NPE in MediaInfoFragment

Geoffrey Métais git at videolan.org
Tue Jun 14 11:01:50 CEST 2016


vlc-android | branch: 2.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jun 13 15:40:50 2016 +0200| [d89cceb04ac93dd765360e1018ae026ff8126ddc] | committer: Geoffrey Métais

Avoid NPE in MediaInfoFragment

(cherry picked from commit 95ec188284540e44b65064cfd1a3dfee3239daf7)

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

 .../videolan/vlc/gui/video/MediaInfoFragment.java   | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
index 3201acb..ead29f0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
@@ -173,10 +173,11 @@ public class MediaInfoFragment extends ListFragment {
         @Override
         public void run() {
             File itemFile = new File(Uri.decode(mItem.getLocation().substring(5)));
-            if (!itemFile.canWrite())
+            if (!itemFile.canWrite() && mHandler != null)
                 mHandler.obtainMessage(HIDE_DELETE).sendToTarget();
             long length = itemFile.length();
-            mHandler.obtainMessage(NEW_SIZE, Long.valueOf(length)).sendToTarget();
+            if (mHandler != null)
+                mHandler.obtainMessage(NEW_SIZE, Long.valueOf(length)).sendToTarget();
             if (mItem.getType() == MediaWrapper.TYPE_VIDEO)
                 checkSubtitles(itemFile);
         }
@@ -214,10 +215,8 @@ public class MediaInfoFragment extends ListFragment {
             if (!Extensions.SUBTITLES.contains(extension))
                 continue;
 
-            if (mHandler == null || Thread.interrupted()) {
+            if (mHandler == null || Thread.interrupted())
                 return;
-            }
-
             if (filename.startsWith(videoName)) {
                 mHandler.obtainMessage(SHOW_SUBTITLES).sendToTarget();
                 return;
@@ -245,7 +244,8 @@ public class MediaInfoFragment extends ListFragment {
             mMedia = new Media(libVlc, mItem.getUri());
             mMedia.parse();
 
-            mHandler.sendEmptyMessage(NEW_TEXT);
+            if (mHandler != null)
+                mHandler.sendEmptyMessage(NEW_TEXT);
 
             DisplayMetrics screen = new DisplayMetrics();
             getActivity().getWindowManager().getDefaultDisplay().getMetrics(screen);
@@ -272,10 +272,8 @@ public class MediaInfoFragment extends ListFragment {
             } else
                 return;
 
-            if (mHandler == null || Thread.interrupted()) {
+            if (mHandler == null || Thread.interrupted())
                 return;
-            }
-
             mHandler.sendEmptyMessage(NEW_IMAGE);
         }
     };
@@ -308,7 +306,7 @@ public class MediaInfoFragment extends ListFragment {
             mAdapter.add(track);
         }
 
-        if (hasSubs)
+        if (hasSubs && mHandler != null)
             mHandler.obtainMessage(SHOW_SUBTITLES).sendToTarget();
     }
 
@@ -324,7 +322,8 @@ public class MediaInfoFragment extends ListFragment {
                 public void run() {
                     FileUtils.deleteFile(mItem.getUri().getPath());
                     MediaDatabase.getInstance().removeMedia(mItem.getUri());
-                    mHandler.sendEmptyMessage(EXIT);
+                    if (mHandler != null)
+                        mHandler.sendEmptyMessage(EXIT);
                 }
             });
         }



More information about the Android mailing list