Buggy code:
@ SuppressWarnings ( "nls" ) public class Calendars { public static final String CALENDAR_CONTENT_CALENDARS = "calendars" ; public static final String CALENDAR_CONTENT_EVENTS = "events" ; private static final String ID_COLUMN_NAME = "_id" ; private static final boolean USE_ICS_NAMES = ( AndroidUtilities . getSdkVersion ( ) ) >= 14 ; private static final String DISPLAY_COLUMN_NAME = ( Calendars . USE_ICS_NAMES ) ? CalendarContract . Calendars . CALENDAR_DISPLAY_NAME : "displayName" ; private static final String ACCES_LEVEL_COLUMN_NAME = ( Calendars . USE_ICS_NAMES ) ? CalendarContract . Calendars . CALENDAR_ACCESS_LEVEL : "access_level" ; private static final String [ ] CALENDARS_PROJECTION = new String [ ] { Calendars . ID_COLUMN_NAME , Calendars . DISPLAY_COLUMN_NAME } ; private static final String CALENDARS_WHERE = ( Calendars . ACCES_LEVEL_COLUMN_NAME ) + ">=<seq2seq4repair_space>500" ; private static final String CALENDARS_SORT = ( Calendars . DISPLAY_COLUMN_NAME ) + "<seq2seq4repair_space>ASC" ; public static Uri getCalendarContentUri ( String table ) { } private static Uri getIcsUri ( String table ) { } public static String getCalendarPackage ( ) { } public static class CalendarResult { public String [ ] calendars ; public String [ ] calendarIds ; public int defaultIndex = - 1 ; } public static Calendars . CalendarResult getCalendars ( ) { Context context = ContextManager . getContext ( ) ; ContentResolver cr = context . getContentResolver ( ) ; Resources r = context . getResources ( ) ; Cursor c = cr . query ( Calendars . getCalendarContentUri ( Calendars . CALENDAR_CONTENT_CALENDARS ) , Calendars . CALENDARS_PROJECTION , Calendars . CALENDARS_WHERE , null , Calendars . CALENDARS_SORT ) ; try { String defaultSetting = Preferences . getStringValue ( gcal_p_default ) ; Calendars . CalendarResult result = new Calendars . CalendarResult ( ) ; if ( ( c == null ) || ( ( c . getCount ( ) ) == 0 ) ) { result . calendars = new String [ ] { r . getString ( gcal_GCP_default ) } ; result . calendarIds = new String [ ] { null } ; result . defaultIndex = 0 ; return result ; } int calendarCount = c . getCount ( ) ; result . calendars = new String [ calendarCount ] ; result . calendarIds = new String [ calendarCount ] ; int row = 0 ; int idColumn = c . getColumnIndex ( Calendars . ID_COLUMN_NAME ) ; int nameColumn = c . getColumnIndex ( Calendars . DISPLAY_COLUMN_NAME ) ; while ( c . moveToNext ( ) ) { String id = c . getString ( idColumn ) ; String name = c . getString ( nameColumn ) ; result . calendars [ row ] = name ; result . calendarIds [ row ] = id ; if ( ( defaultSetting != null ) && ( defaultSetting . equals ( id ) ) ) { result . defaultIndex = row ; } row ++ ; } <START_BUG> if ( ( ( result . defaultIndex ) == ( - 1 ) ) || ( ( result . defaultIndex ) >= calendarCount ) ) { <END_BUG> result . defaultIndex = 0 ; } return result ; } finally { if ( c != null ) c . close ( ) ; } } public static void initCalendarsPreference ( Context context , ListPreference listPreference ) { } public static void setDefaultCalendar ( String defaultCalendar ) { } public static String getDefaultCalendar ( ) { } No newline ; at end ; of file ; }

Fix:
if ( ( result . defaultIndex ) >= calendarCount ) {