From 00284d5392b845bd984c105140db627c4be7a98a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 17 Dec 2025 10:10:33 +0000 Subject: [PATCH] Safely handle Contact photo cursor and log exceptions Fixed an issue where an exception during contact photo retrieval was ignored and could potentially lead to a NullPointerException if the cursor was null. The cursor is now properly checked for null before access, and closed safely in the finally block. Exceptions are now logged using `java.util.logging.Logger` to match existing patterns in the file. --- .../impl/android/AndroidContactsManager.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Ports/Android/src/com/codename1/impl/android/AndroidContactsManager.java b/Ports/Android/src/com/codename1/impl/android/AndroidContactsManager.java index d20531d136..359ebc45b1 100644 --- a/Ports/Android/src/com/codename1/impl/android/AndroidContactsManager.java +++ b/Ports/Android/src/com/codename1/impl/android/AndroidContactsManager.java @@ -100,19 +100,21 @@ public static InputStream loadContactPhoto(ContentResolver cr, long id, long pho Uri photoUri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, photo_id); - Cursor c = cr.query(photoUri, new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null); + Cursor c = null; try { - if (c.moveToFirst()) { + c = cr.query(photoUri, new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null); + if (c != null && c.moveToFirst()) { photoBytes = c.getBlob(0); } } catch (Exception e) { - // TODO: handle exception - e.printStackTrace(); + Logger.getLogger(AndroidContactsManager.class.getName()).log(Level.SEVERE, null, e); } finally { - c.close(); + if (c != null) { + c.close(); + } } if (photoBytes != null) {