proper null checks and closing of cursors everywhere

This commit is contained in:
Vincent Breitmoser
2014-05-08 15:56:32 +02:00
parent 79117b1ef8
commit cbc3988628
6 changed files with 187 additions and 146 deletions

View File

@@ -112,16 +112,18 @@ public class FileHelper {
if ("content".equalsIgnoreCase(uri.getScheme())) {
String[] projection = {"_data"};
Cursor cursor = null;
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
try {
cursor = context.getContentResolver().query(uri, projection, null, null, null);
int columnIndex = cursor.getColumnIndexOrThrow("_data");
if (cursor.moveToFirst()) {
if (cursor != null && cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndexOrThrow("_data");
return cursor.getString(columnIndex);
}
} catch (Exception e) {
// Eat it
} finally {
if (cursor != null) {
cursor.close();
}
}
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();