From 2a34ece571578bb76caf88626019a8edf146bb9e Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Mon, 30 Jan 2017 00:03:51 -0500 Subject: [PATCH] Stop Conversations force closing over sqlite errors due to long messages --- src/main/java/eu/siacs/conversations/entities/Message.java | 2 ++ .../eu/siacs/conversations/persistance/DatabaseBackend.java | 6 ++++-- .../eu/siacs/conversations/services/ExportLogsService.java | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index c53bb061e..77fb2545d 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -154,6 +154,8 @@ public class Message extends AbstractEntity { } } catch (InvalidJidException e) { jid = null; + } catch (IllegalStateException e) { + return null; // message too long? } Jid trueCounterpart; try { diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index e66870f24..255854e41 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -636,8 +636,10 @@ public class DatabaseBackend extends SQLiteOpenHelper { cursor.moveToLast(); do { Message message = Message.fromCursor(cursor); - message.setConversation(conversation); - list.add(message); + if (message != null) { + message.setConversation(conversation); + list.add(message); + } } while (cursor.moveToPrevious()); } cursor.close(); diff --git a/src/main/java/eu/siacs/conversations/services/ExportLogsService.java b/src/main/java/eu/siacs/conversations/services/ExportLogsService.java index 51eced059..91df3e010 100644 --- a/src/main/java/eu/siacs/conversations/services/ExportLogsService.java +++ b/src/main/java/eu/siacs/conversations/services/ExportLogsService.java @@ -84,6 +84,8 @@ public class ExportLogsService extends Service { BufferedWriter bw = null; try { for (Message message : mDatabaseBackend.getMessagesIterable(conversation)) { + if (message == null) + continue; if (message.getType() == Message.TYPE_TEXT || message.hasFileOnRemoteHost()) { String date = simpleDateFormat.format(new Date(message.getTimeSent())); if (bw == null) {