From 9496ff0f4dfee9372c18425d859bffa8b28a0bd4 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Tue, 3 Apr 2012 17:42:49 -0700 Subject: [PATCH] Catch a potential crash and bail out in rescheduling repeating calendar events --- .../plugin-src/com/todoroo/astrid/gcal/GCalHelper.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/gcal/GCalHelper.java b/astrid/plugin-src/com/todoroo/astrid/gcal/GCalHelper.java index db812001d..73a8eb2a9 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gcal/GCalHelper.java +++ b/astrid/plugin-src/com/todoroo/astrid/gcal/GCalHelper.java @@ -5,6 +5,7 @@ import java.util.TimeZone; import android.content.ContentResolver; import android.content.ContentValues; import android.database.Cursor; +import android.database.CursorIndexOutOfBoundsException; import android.net.Uri; import android.text.TextUtils; import android.text.format.Time; @@ -106,6 +107,10 @@ public class GCalHelper { Uri eventUri = Uri.parse(taskUri); String calendarId = getCalendarId(eventUri, cr); + if (calendarId == null) { // Bail out, no calendar id + task.setValue(Task.CALENDAR_URI, ""); //$NON-NLS-1$ + return; + } ContentValues cv = new ContentValues(); cv.put(CALENDAR_ID_COLUMN, calendarId); @@ -115,9 +120,11 @@ public class GCalHelper { private static String getCalendarId(Uri uri, ContentResolver cr) { Cursor calendar = cr.query(uri, new String[] { CALENDAR_ID_COLUMN }, null, null, null); - calendar.moveToFirst(); try { + calendar.moveToFirst(); return calendar.getString(0); + } catch (CursorIndexOutOfBoundsException e) { + return null; } finally { calendar.close(); }