[Android] libvlc: throw a IndexOutOfBoundsException instead of returning null

Thomas Guillem git at videolan.org
Fri May 29 09:51:57 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri May 29 09:48:15 2015 +0200| [5bd843d5bff1eb3f9d3af38e585c76b67ab75676] | committer: Thomas Guillem

libvlc: throw a IndexOutOfBoundsException instead of returning null

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=5bd843d5bff1eb3f9d3af38e585c76b67ab75676
---

 libvlc/src/org/videolan/libvlc/MediaList.java         |    5 ++---
 libvlc/src/org/videolan/libvlc/util/MediaBrowser.java |    7 ++++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/MediaList.java b/libvlc/src/org/videolan/libvlc/MediaList.java
index 056dead..56e81d2 100644
--- a/libvlc/src/org/videolan/libvlc/MediaList.java
+++ b/libvlc/src/org/videolan/libvlc/MediaList.java
@@ -139,9 +139,8 @@ public class MediaList extends VLCObject {
      * @return Media hold by MediaList, Should NOT be released.
      */
     public synchronized Media getMediaAt(int index) {
-        if (index < 0 || index > getCount())
-            return null;
-        return mMediaArray.get(index);
+        if (index < 0 || index >= getCount())
+            throw new IndexOutOfBoundsException();
     }
 
     @Override
diff --git a/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java b/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java
index 8a50aa4..59d8c7d 100644
--- a/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java
+++ b/libvlc/src/org/videolan/libvlc/util/MediaBrowser.java
@@ -187,9 +187,10 @@ public class MediaBrowser {
      * Get a media at a specified index.
      */
     public synchronized Media getMediaAt(int index) {
-        return index >= 0 && index < getMediaCount() ?
-                mBrowserMediaList != null ? mBrowserMediaList.getMediaAt(index) :
-                mDiscovererMediaArray.get(index) : null;
+        if (index < 0 || index >= getMediaCount())
+            throw new IndexOutOfBoundsException();
+        return mBrowserMediaList != null ? mBrowserMediaList.getMediaAt(index) :
+                mDiscovererMediaArray.get(index);
     }
 
     private MediaList.EventListener mBrowserMediaListEventListener = new MediaList.EventListener() {



More information about the Android mailing list