[Android] MediaWrapperList: Avoid IndexOutOfBoundsException

Geoffrey Métais git at videolan.org
Mon Feb 18 17:46:21 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 18 17:25:30 2019 +0100| [e776ede32bd9dad456fb7c1f15332b9cfc1dd39c] | committer: Geoffrey Métais

MediaWrapperList: Avoid IndexOutOfBoundsException

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

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

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java b/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java
index 744719e55..9d9001b88 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaWrapperList.java
@@ -93,7 +93,8 @@ public class MediaWrapperList {
     }
 
     public synchronized void insert(int position, MediaWrapper media) {
-        mInternalList.add(position, media);
+        if (position < 0) return;
+        mInternalList.add(Math.min(position, mInternalList.size()), media);
         signalEventListeners(EVENT_ADDED, position, -1, media.getLocation());
         if (media.getType() == MediaWrapper.TYPE_VIDEO)
             ++mVideoCount;
@@ -121,8 +122,7 @@ public class MediaWrapperList {
     }
 
     public synchronized void remove(int position) {
-        if (!isValid(position))
-            return;
+        if (!isValid(position)) return;
         if (mInternalList.get(position).getType() == MediaWrapper.TYPE_VIDEO)
             --mVideoCount;
         String uri = mInternalList.get(position).getLocation();



More information about the Android mailing list