[Android] Avoid NPE instead of catching it

Geoffrey Métais git at videolan.org
Wed Feb 18 10:33:46 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb 18 10:33:14 2015 +0100| [09819e282f88c5dc7c18dd44173cc964431a0f9a] | committer: Geoffrey Métais

Avoid NPE instead of catching it

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

 vlc-android/src/org/videolan/vlc/util/Util.java |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 2ac0320..eaa433e 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -282,12 +282,15 @@ public class Util {
     }
 
     public static boolean close(Closeable closeable) {
-        try {
-            closeable.close();
-            return true;
-        } catch (IOException e) {
-            return false;
-        } catch (NullPointerException e) {
-            return false;}
+        if (closeable != null) {
+            try {
+                closeable.close();
+                return true;
+            } catch (IOException e) {
+                return false;
+            }
+        } else {
+                return false;
+        }
     }
 }



More information about the Android mailing list