[Android] Prevent IllegalArgumentException

Geoffrey Métais git at videolan.org
Wed Apr 12 14:59:25 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Apr 11 17:04:07 2017 +0200| [ca9af24c22fcd2fdbc78fbdfa6a2435bd336e5fd] | committer: Geoffrey Métais

Prevent IllegalArgumentException

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

 vlc-android/src/org/videolan/vlc/util/FileUtils.java | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.java b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
index fb4b7e4..5025189 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.java
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.java
@@ -107,13 +107,18 @@ public class FileUtils {
     public static String getPathFromURI(Uri contentUri) {
         Cursor cursor = null;
         try {
-            String[] proj = { MediaStore.Images.Media.DATA };
-            cursor = VLCApplication.getAppContext().getContentResolver().query(contentUri,  proj, null, null, null);
+            String[] proj = {MediaStore.Images.Media.DATA};
+            cursor = VLCApplication.getAppContext().getContentResolver().query(contentUri, proj, null, null, null);
+            if (cursor == null)
+                return "";
             int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
             cursor.moveToFirst();
             return cursor.getString(column_index);
+        } catch (IllegalArgumentException e) {
+                return "";
         } finally {
-            Util.close(cursor);
+            if (cursor != null && !cursor.isClosed())
+                cursor.close();
         }
     }
 
@@ -270,7 +275,7 @@ public class FileUtils {
     }
 
     public static boolean canWrite(String path){
-        if (path == null)
+        if (TextUtils.isEmpty(path))
             return false;
         if (path.startsWith("file://"))
             path = path.substring(7);



More information about the Android mailing list