Bug 1261965 - Correct potential NullPointerException in FilePickerResultHandler. r=grisha
MozReview-Commit-ID: 7a8jV4vRCH2
--- a/mobile/android/base/java/org/mozilla/gecko/FilePickerResultHandler.java
+++ b/mobile/android/base/java/org/mozilla/gecko/FilePickerResultHandler.java
@@ -86,32 +86,31 @@ class FilePickerResultHandler implements
if ("file".equals(uri.getScheme())) {
String path = uri.getPath();
sendResult(path == null ? "" : path);
return;
}
final FragmentActivity fa = (FragmentActivity) GeckoAppShell.getGeckoInterface().getActivity();
final LoaderManager lm = fa.getSupportLoaderManager();
+
// Finally, Video pickers and some file pickers may return a content provider.
- Cursor cursor = null;
- try {
- // Try a query to make sure the expected columns exist
- final ContentResolver cr = fa.getContentResolver();
- cursor = cr.query(uri, new String[] { MediaStore.Video.Media.DATA }, null, null, null);
-
- int index = cursor.getColumnIndex(MediaStore.Video.Media.DATA);
- if (index >= 0) {
- lm.initLoader(intent.hashCode(), null, new VideoLoaderCallbacks(uri));
- return;
- }
- } catch(Exception ex) {
- // We'll try a different loader below
- } finally {
- if (cursor != null) {
+ final ContentResolver cr = fa.getContentResolver();
+ final Cursor cursor = cr.query(uri, new String[] { MediaStore.Video.Media.DATA }, null, null, null);
+ if (cursor != null) {
+ try {
+ // Try a query to make sure the expected columns exist
+ int index = cursor.getColumnIndex(MediaStore.Video.Media.DATA);
+ if (index >= 0) {
+ lm.initLoader(intent.hashCode(), null, new VideoLoaderCallbacks(uri));
+ return;
+ }
+ } catch (Exception ex) {
+ // We'll try a different loader below
+ } finally {
cursor.close();
}
}
lm.initLoader(uri.hashCode(), null, new FileLoaderCallbacks(uri, cacheDir, tabId));
}
public String generateImageName() {