[Android] Prevent IndexOutOfBoundsException

Geoffrey Métais git at videolan.org
Tue Jun 6 18:00:13 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jun  6 17:54:18 2017 +0200| [a9f1009b395c34f905b431998bd39f5ed29acdb2] | committer: Geoffrey Métais

Prevent IndexOutOfBoundsException

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

 .../src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java     | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index c67a54f2b..e14ecdae5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -178,18 +178,21 @@ public class BaseBrowserAdapter extends BaseQueuedAdapter<ArrayList<MediaLibrary
 
         public void onClick(View v){
             int position = getLayoutPosition();
-            fragment.onClick(v, position, mMediaList.get(position));
+            if (position < mMediaList.size() && position >= 0)
+                fragment.onClick(v, position, mMediaList.get(position));
         }
 
         public void onMoreClick(View v) {
             int position = getLayoutPosition();
-            fragment.onCtxClick(v, position, mMediaList.get(position));
+            if (position < mMediaList.size() && position >= 0)
+                fragment.onCtxClick(v, position, mMediaList.get(position));
         }
 
         @Override
         public boolean onLongClick(View v) {
             int position = getLayoutPosition();
-            return fragment.onLongClick(v, position, mMediaList.get(position));
+            return position < mMediaList.size() && position >= 0
+                && fragment.onLongClick(v, position, mMediaList.get(position));
         }
 
         private void setViewBackground(boolean focus, boolean selected) {



More information about the Android mailing list