From d311e39569226f74f1ae8d1b948b88e6311a28d8 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 25 Feb 2022 14:44:46 +0100 Subject: [PATCH] code clean up --- .../java/eu/siacs/conversations/utils/MimeUtils.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/utils/MimeUtils.java b/src/main/java/eu/siacs/conversations/utils/MimeUtils.java index c0a6f4cfd..90f27f65f 100644 --- a/src/main/java/eu/siacs/conversations/utils/MimeUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/MimeUtils.java @@ -568,11 +568,15 @@ public final class MimeUtils { } private static String getDisplayName(final Context context, final Uri uri) { - try (Cursor cursor = context.getContentResolver().query(uri, null, null, null, null)) { + try (final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null)) { if (cursor != null && cursor.moveToFirst()) { - return cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); + final int index = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); + if (index == -1) { + return null; + } + return cursor.getString(index); } - } catch (Exception e) { + } catch (final Exception e) { return null; } return null;