From 04eeb8f18f6d8be2231d60d04b1fb84e3883bf37 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 24 Oct 2020 13:13:47 -0700 Subject: [PATCH] don't crash when number of INVITEMEANS changes This won't impact shipping code, but if during development I add then remove a new INVITEMEANS I can crash with AIOOB trying to load by ordinal. So check first. --- .../main/java/org/eehouse/android/xw4/DBUtils.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java index 646ad43d2..0025d7f6d 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java @@ -646,11 +646,15 @@ public class DBUtils { int indxTS = cursor.getColumnIndex( DBHelper.TIMESTAMP ); int indxTrgt = cursor.getColumnIndex( DBHelper.TARGET ); + InviteMeans[] values = InviteMeans.values(); while ( cursor.moveToNext() ) { - InviteMeans means = InviteMeans.values()[cursor.getInt( indxMns )]; - Date ts = new Date(cursor.getLong(indxTS)); - String target = cursor.getString( indxTrgt ); - result.addEntry( means, target, ts ); + int ordinal = cursor.getInt( indxMns ); + if ( ordinal < values.length ) { + InviteMeans means = values[ordinal]; + Date ts = new Date(cursor.getLong(indxTS)); + String target = cursor.getString( indxTrgt ); + result.addEntry( means, target, ts ); + } } } cursor.close();