[Android] Prevent NPE in browsers context menu

Geoffrey Métais git at videolan.org
Mon Nov 27 15:53:52 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Nov 27 15:21:54 2017 +0100| [39b6afc333b84f75dc358f152f71b8d125167bd8] | committer: Geoffrey Métais

Prevent NPE in browsers context menu

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

 vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 5aee19028..fe76e0a2f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -503,6 +503,7 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
     @Override
     protected void inflate(Menu menu, int position) {
         MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
+        if (mw == null) return;
         int type = mw.getType();
         MenuInflater inflater = getActivity().getMenuInflater();
         inflater.inflate(type == MediaWrapper.TYPE_DIR ? R.menu.directory_view_dir : R.menu.directory_view_file, menu);
@@ -510,6 +511,7 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
 
     protected void setContextMenuItems(Menu menu, int position) {
         final MediaWrapper mw = (MediaWrapper) mAdapter.getItem(position);
+        if (mw == null) return;
         final int type = mw.getType();
         boolean canWrite = this instanceof FileBrowserFragment && FileUtils.canWrite(mw.getUri().getPath());
         if (type == MediaWrapper.TYPE_DIR) {



More information about the Android mailing list