Skip to content

Commit

Permalink
Merge pull request #2338 from sepinf-inc/#2337_FixWAMessageCompare
Browse files Browse the repository at this point in the history
Review WhatsApp Message compareTo() to avoid "Comparison method violates its general contract" exceptions.
  • Loading branch information
lfcnassif authored Oct 15, 2024
2 parents cdb5ebe + acd9e16 commit 474f4b9
Showing 1 changed file with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public void setMessageTemplate(MessageTemplate messageTemplate) {
}

public long getSortId() {
return sortId;
return sortId != 0 ? sortId : timeStamp != null ? timeStamp.getTime() : id;
}

public void setSortId(long sortId) {
Expand Down Expand Up @@ -690,18 +690,6 @@ 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;
}
}
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(getSortId(), o.getSortId());
}
}

0 comments on commit 474f4b9

Please sign in to comment.