Bug 1502721 Crash in java.lang.NumberFormatException: at java.lang.Long.parseLong(Long.java) r=JanH
authorAndrei Lazar <andrei.a.lazar@softvision.ro>
Wed, 28 Nov 2018 20:45:44 +0000
changeset 507816 9fda62ff71b434990997d833a373a229906eb2db
parent 507815 95c294286e66c5e4d3ae15706247ad95357b34fd
child 507817 c35dea45f131cc498de25030f91f6178751aec71
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJanH
bugs1502721
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1502721 Crash in java.lang.NumberFormatException: at java.lang.Long.parseLong(Long.java) r=JanH Added catch for NumberFormatException that may be thrown when trying to open some downloaded files with Fennec. Differential Revision: https://phabricator.services.mozilla.com/D12773
mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ContentUriUtils.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ContentUriUtils.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/ContentUriUtils.java
@@ -19,16 +19,17 @@ package org.mozilla.gecko.util;
 import android.content.ContentUris;
 import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Environment;
 import android.provider.DocumentsContract;
 import android.provider.MediaStore;
+import android.text.TextUtils;
 
 /**
  * Based on https://github.com/iPaulPro/aFileChooser/blob/48d65e6649d4201407702b0390326ec9d5c9d17c/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java
  */
 public class ContentUriUtils {
     /**
      * Get a file path from a Uri. This will get the the path for Storage Access
      * Framework Documents, as well as the _data field for the MediaStore and
@@ -56,22 +57,31 @@ public class ContentUriUtils {
                 if ("primary".equalsIgnoreCase(type)) {
                     return Environment.getExternalStorageDirectory() + "/" + split[1];
                 }
 
                 // TODO handle non-primary volumes
             }
             // DownloadsProvider
             else if (isDownloadsDocument(uri)) {
-
                 final String id = DocumentsContract.getDocumentId(uri);
-                final Uri contentUri = ContentUris.withAppendedId(
-                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
-
-                return getDataColumn(context, contentUri, null, null);
+                // workaround for issue (https://bugzilla.mozilla.org/show_bug.cgi?id=1502721) and
+                // as per https://github.com/Yalantis/uCrop/issues/318#issuecomment-333066640
+                if (!TextUtils.isEmpty(id)) {
+                    if (id.startsWith("raw:")) {
+                        return id.replaceFirst("raw:", "");
+                    }
+                    try {
+                        final Uri contentUri = ContentUris.withAppendedId(
+                                Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
+                        return getDataColumn(context, contentUri, null, null);
+                    } catch (NumberFormatException e) {
+                        return null;
+                    }
+                }
             }
             // MediaProvider
             else if (isMediaDocument(uri)) {
                 final String docId = DocumentsContract.getDocumentId(uri);
                 final String[] split = docId.split(":");
                 final String type = split[0];
 
                 Uri contentUri = null;