[Android] libvlc: throw an exception instead of undefined behavior

Thomas Guillem git at videolan.org
Fri May 29 10:03:55 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri May 29 10:01:23 2015 +0200| [a562cdce79eb87c4f727150f9fedce8843feebb7] | committer: Thomas Guillem

libvlc: throw an exception instead of undefined behavior

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

 libvlc/src/org/videolan/libvlc/Media.java          |   12 ++++++----
 .../src/org/videolan/libvlc/MediaDiscoverer.java   |   23 +++++++++++---------
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index f62b295..90eccfc 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -325,20 +325,24 @@ public class Media extends VLCObject {
     }
 
     /**
-     * Get the subItems MediaList associated with the Media.
+     * Get the subItems MediaList associated with the Media. This Media should be alive (not released).
      *
      * @return subItems as a MediaList. This MediaList should be released with {@link #release()}.
      */
     public synchronized MediaList subItems() {
-        if (mSubItems == null && !isReleased())
+        if (isReleased())
+            throw new IllegalStateException("Media is released");
+        if (mSubItems == null)
             mSubItems = new MediaList(this);
         mSubItems.retain();
         return mSubItems;
     }
 
     private synchronized void postParse() {
-        // fetch if native, parsed and not fetched
-        if (!isReleased() && (mParseStatus & PARSE_STATUS_PARSING) != 0
+        if (isReleased())
+            throw new IllegalStateException("Media is released");
+        // fetch if parsed and not fetched
+        if ((mParseStatus & PARSE_STATUS_PARSING) != 0
                 && (mParseStatus & PARSE_STATUS_PARSED) == 0) {
             mParseStatus &= ~PARSE_STATUS_PARSING;
             mParseStatus |= PARSE_STATUS_PARSED;
diff --git a/libvlc/src/org/videolan/libvlc/MediaDiscoverer.java b/libvlc/src/org/videolan/libvlc/MediaDiscoverer.java
index df823a1..67c8b4e 100644
--- a/libvlc/src/org/videolan/libvlc/MediaDiscoverer.java
+++ b/libvlc/src/org/videolan/libvlc/MediaDiscoverer.java
@@ -35,24 +35,24 @@ public class MediaDiscoverer extends VLCObject {
     }
 
     /**
-     * Starts the discovery.
+     * Starts the discovery. This MediaDiscoverer should be alive (not released).
      *
-     * @return true the serive is started
+     * @return true the service is started
      */
     public boolean start() {
-        if (!isReleased())
-            return nativeStart();
-        else
-            return false;
+        if (isReleased())
+            throw new IllegalStateException("MediaDiscoverer is released");
+        return nativeStart();
     }
 
     /**
-     * Stops the discovery.
+     * Stops the discovery. This MediaDiscoverer should be alive (not released).
      * (You can also call {@link #release() to stop the discovery directly}.
      */
     public void stop() {
-        if (!isReleased())
-            nativeStop();
+        if (isReleased())
+            throw new IllegalStateException("MediaDiscoverer is released");
+        nativeStop();
     }
 
     @Override
@@ -62,11 +62,14 @@ public class MediaDiscoverer extends VLCObject {
 
     /**
      * Get the MediaList associated with the MediaDiscoverer.
+     * This MediaDiscoverer should be alive (not released).
      *
      * @return MediaList. This MediaList should be released with {@link #release()}.
      */
     public synchronized MediaList getMediaList() {
-        if (mMediaList == null && !isReleased())
+        if (isReleased())
+            throw new IllegalStateException("MediaDiscoverer is released");
+        if (mMediaList == null)
             mMediaList = new MediaList(this);
         mMediaList.retain();
         return mMediaList;



More information about the Android mailing list