From be82ac563323ed83427b3ad692650c8283ce5338 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Tue, 3 Sep 2019 20:31:32 +0200 Subject: fix some crashes --- .../messenger/persistance/DatabaseBackend.java | 12 +++++++----- .../de/pixart/messenger/persistance/FileBackend.java | 20 ++++++++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) (limited to 'src/main/java/de/pixart/messenger/persistance') diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index afffa388f..e9f7c0576 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -1009,12 +1009,14 @@ public class DatabaseBackend extends SQLiteOpenHelper { private List getAccounts(SQLiteDatabase db) { List list = new ArrayList<>(); - Cursor cursor = db.query(Account.TABLENAME, null, null, null, null, - null, null); - while (cursor.moveToNext()) { - list.add(Account.fromCursor(cursor)); + try (Cursor cursor = db.query(Account.TABLENAME, null, null, null, null, + null, null)) { + while (cursor.moveToNext()) { + list.add(Account.fromCursor(cursor)); + } + } catch (Exception e) { + e.printStackTrace(); } - cursor.close(); return list; } diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 962496dcb..235547c1d 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -719,7 +719,10 @@ public class FileBackend { frame = metadataRetriever.getFrameAtTime(0); metadataRetriever.release(); frame = resize(frame, size); - } catch (IOException | RuntimeException e) { + } catch (IOException e) { + frame = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); + frame.eraseColor(0xff000000); + } catch (RuntimeException e) { frame = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); frame.eraseColor(0xff000000); } @@ -880,7 +883,9 @@ public class FileBackend { avatar.width = options.outWidth; avatar.type = options.outMimeType; return avatar; - } catch (NoSuchAlgorithmException | IOException e) { + } catch (NoSuchAlgorithmException e) { + return null; + } catch (IOException e) { return null; } finally { close(is); @@ -934,7 +939,11 @@ public class FileBackend { return false; } avatar.size = bytes.length; - } catch (IllegalArgumentException | IOException | NoSuchAlgorithmException e) { + } catch (IllegalArgumentException e) { + return false; + } catch (IOException e) { + return false; + } catch (NoSuchAlgorithmException e) { return false; } finally { close(os); @@ -970,7 +979,10 @@ public class FileBackend { input = rotate(input, getRotation(image)); return cropCenterSquare(input, size); } - } catch (FileNotFoundException | SecurityException e) { + } catch (FileNotFoundException e) { + Log.d(Config.LOGTAG, "unable to open file " + image.toString(), e); + return null; + } catch (SecurityException e) { Log.d(Config.LOGTAG, "unable to open file " + image.toString(), e); return null; } finally { -- cgit v1.2.3