From fbf64fa1e98b9575c51f3b13b8fc5bc08ba16575 Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Tue, 5 Dec 2017 21:48:17 +0100 Subject: [PATCH] fix NPE in MediaUtils.getMediaSize --- .../main/java/com/keylesspalace/tusky/ComposeActivity.java | 2 +- .../main/java/com/keylesspalace/tusky/util/MediaUtils.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java index 64ee247c..fb44a3ab 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java @@ -1355,11 +1355,11 @@ public final class ComposeActivity extends BaseActivity private void pickMedia(Uri uri, long mediaSize) { - ContentResolver contentResolver = getContentResolver(); if (mediaSize == MediaUtils.MEDIA_SIZE_UNKNOWN) { displayTransientError(R.string.error_media_upload_opening); return; } + ContentResolver contentResolver = getContentResolver(); String mimeType = contentResolver.getType(uri); if (mimeType != null) { String topLevelType = mimeType.substring(0, mimeType.indexOf('/')); diff --git a/app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.java b/app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.java index 424cbdc5..40cd566a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/MediaUtils.java @@ -24,6 +24,7 @@ import android.media.MediaMetadataRetriever; import android.media.ThumbnailUtils; import android.net.Uri; import android.provider.OpenableColumns; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.Px; @@ -66,7 +67,8 @@ public class MediaUtils { * * @return the size of the media or {@link MediaUtils#MEDIA_SIZE_UNKNOWN} */ - public static long getMediaSize(ContentResolver contentResolver, Uri uri) { + public static long getMediaSize(@NonNull ContentResolver contentResolver, @Nullable Uri uri) { + if(uri == null) return MEDIA_SIZE_UNKNOWN; long mediaSize; Cursor cursor = contentResolver.query(uri, null, null, null, null); if (cursor != null) {