From 61efb96fc83ec9acccb4fdd3e55cb3a24e6ecaf9 Mon Sep 17 00:00:00 2001 From: tc-wleite Date: Tue, 15 Oct 2024 11:46:31 -0300 Subject: [PATCH 1/4] '#2337: Review WhatsApp Message compareTo() to avoid exceptions. --- .../java/iped/parsers/whatsapp/Message.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java index f9fae1a459..c8cad7e047 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java @@ -637,7 +637,7 @@ public void setMessageTemplate(MessageTemplate messageTemplate) { } public long getSortId() { - return sortId; + return sortId == 0 ? id : sortId; } public void setSortId(long sortId) { @@ -690,18 +690,14 @@ public static enum MessageQuotedType { @Override public int compareTo(Message o) { - if (getSortId() != 0 && o.getSortId() != 0) { - int comp = Long.compare(getSortId(), o.getSortId()); - if (comp != 0) { - return comp; - } + int comp = Long.compare(getSortId(), o.getSortId()); + if (comp != 0) { + return comp; } - if (getTimeStamp() != null && o.getTimeStamp() != null) { - int comp = getTimeStamp().compareTo(o.getTimeStamp()); - if (comp != 0) { - return comp; - } - } - return Long.compare(getId(), o.getId()); + return Long.compare(getTime(), o.getTime()); + } + + private long getTime() { + return timeStamp == null ? 0 : timeStamp.getTime(); } } From b4d0524f55fcee93f7674ef9418ca454b8b2d8d3 Mon Sep 17 00:00:00 2001 From: tc-wleite Date: Tue, 15 Oct 2024 13:22:46 -0300 Subject: [PATCH 2/4] '#2337: Simplify last commit changes, keeping behavior for old DBs. --- .../src/main/java/iped/parsers/whatsapp/Message.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java index c8cad7e047..1ea33431d4 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java @@ -637,7 +637,7 @@ public void setMessageTemplate(MessageTemplate messageTemplate) { } public long getSortId() { - return sortId == 0 ? id : sortId; + return sortId == 0 ? timeStamp == null ? 0 : timeStamp.getTime() : sortId; } public void setSortId(long sortId) { @@ -690,14 +690,6 @@ public static enum MessageQuotedType { @Override public int compareTo(Message o) { - int comp = Long.compare(getSortId(), o.getSortId()); - if (comp != 0) { - return comp; - } - return Long.compare(getTime(), o.getTime()); - } - - private long getTime() { - return timeStamp == null ? 0 : timeStamp.getTime(); + return Long.compare(getSortId(), o.getSortId()); } } From 39c1a37c7746ff8e90cf586cedd65132d4e8407f Mon Sep 17 00:00:00 2001 From: tc-wleite Date: Tue, 15 Oct 2024 13:24:48 -0300 Subject: [PATCH 3/4] '#2337: Fix last commit. --- .../src/main/java/iped/parsers/whatsapp/Message.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java index 1ea33431d4..39048b920e 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java @@ -637,7 +637,7 @@ public void setMessageTemplate(MessageTemplate messageTemplate) { } public long getSortId() { - return sortId == 0 ? timeStamp == null ? 0 : timeStamp.getTime() : sortId; + return sortId == 0 ? timeStamp == null ? 0 : timeStamp.getTime() : id; } public void setSortId(long sortId) { From acd9e16f56153f88486141b64c444c3fae118b08 Mon Sep 17 00:00:00 2001 From: tc-wleite Date: Tue, 15 Oct 2024 14:36:55 -0300 Subject: [PATCH 4/4] '#2337: Fix last commits. Clearer priority: sortId -> timeStamp -> id. --- .../src/main/java/iped/parsers/whatsapp/Message.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java index 39048b920e..7feb40419f 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java @@ -637,7 +637,7 @@ public void setMessageTemplate(MessageTemplate messageTemplate) { } public long getSortId() { - return sortId == 0 ? timeStamp == null ? 0 : timeStamp.getTime() : id; + return sortId != 0 ? sortId : timeStamp != null ? timeStamp.getTime() : id; } public void setSortId(long sortId) {