From ba99eb0838f0efdac17d6c1f7b823f006d397155 Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 26 Oct 2020 13:04:28 -0700 Subject: [PATCH] avoid crash (maybe on corrupt data?) --- .../eehouse/android/xw4/BTInviteDelegate.java | 16 +++++++++++++--- .../org/eehouse/android/xw4/InviteDelegate.java | 6 ++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java index f8c7680c2..e396bee62 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java @@ -128,9 +128,19 @@ public class BTInviteDelegate extends InviteDelegate Collections.sort( pairs, new Comparator() { @Override public int compare( TwoStringPair rec1, TwoStringPair rec2 ) { - long val1 = stamps.get( rec1.str2 ); - long val2 = stamps.get( rec2.str2 ); - return (int)(val2 - val1); + int result = 0; + try { + long val1 = stamps.get( rec1.str2 ); + long val2 = stamps.get( rec2.str2 ); + if ( val2 > val1 ) { + result = 1; + } else if ( val1 > val2 ) { + result = -1; + } + } catch ( Exception ex ) { + Log.e( TAG, "ex %s on %s vs %s", ex, rec1, rec2 ); + } + return result; } }); } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java index 22b47a171..2ad5d8ffe 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java @@ -82,6 +82,12 @@ abstract class InviteDelegate extends DelegateBase } return result; } + + @Override + public String toString() + { + return String.format( "{dev: \"%s\", str2: \"%s\"}", mDev, str2 ); + } } public static final String DEVS = "DEVS";