Buggy code:
public class MainActivity extends Activity implements WeekView . EmptyViewClickListener , WeekView . EventClickListener , WeekView . EventLongPressListener , WeekView . MonthChangeListener { private static final String TAG = "MainActivity.TAG" ; private ArrayList < WeekViewEvent > mNewEvents ; private static final int TYPE_DAY_VIEW = 1 ; private static final int TYPE_THREE_DAY_VIEW = 2 ; private int mWeekViewType = MainActivity . TYPE_THREE_DAY_VIEW ; private WeekView mWeekView ; private EventEntryDatasource database ; public int extra_hour = 0 ; public boolean add_time = false ; public WeekViewEvent change_event ; public long delete_id = - 1 ; ArrayList < EventEntry > entries ; @ Override protected void onCreate ( Bundle savedInstanceState ) { } @ Override protected void onResume ( ) { } private ArrayList < WeekViewEvent > getWeekViewEvents ( ArrayList < EventEntry > entries ) { } @ Override public void onEmptyViewClicked ( Calendar time ) { } @ Override public List < WeekViewEvent > onMonthChange ( int newYear , int newMonth ) { } private ArrayList < WeekViewEvent > getNewEvents ( int year , int month ) { } public static String timeString ( long timeInMills ) { } @ Override public void onEventClick ( WeekViewEvent event , RectF eventRect ) { } public void displayDialog ( int id ) { } public void addTime ( String str ) { } private void deleteItem ( ) { } @ Override public void onEventLongPress ( WeekViewEvent event , RectF eventRect ) { } @ Override protected void onActivityResult ( int requestCode , int resultCode , Intent data ) { } @ Override public boolean onCreateOptionsMenu ( Menu menu ) { } @ Override public boolean onOptionsItemSelected ( MenuItem item ) { } private int dayNumber ( int month ) { } private void arrangeTime ( ) { Log . d ( MainActivity . TAG , "arrangrTime()<seq2seq4repair_space>called" ) ; mergeDataBase ( ) ; ArrayList < EventEntry > en = database . fetchEntries ( ) ; Log . d ( MainActivity . TAG , ( "In<seq2seq4repair_space>arrangeTime<seq2seq4repair_space>number<seq2seq4repair_space>is<seq2seq4repair_space>" + ( en . size ( ) ) ) ) ; Comparator < EventEntry > comparator = new SequenceComparator ( ) ; <START_BUG> PriorityQueue < EventEntry > queue = new PriorityQueue ( 20 , comparator ) ; <END_BUG> for ( EventEntry e : en ) { queue . add ( e ) ; long id = e . getId ( ) ; database . removeEntry ( id ) ; } Calendar now = Calendar . getInstance ( ) ; now . set ( Calendar . HOUR_OF_DAY , ( ( now . get ( Calendar . HOUR_OF_DAY ) ) + 1 ) ) ; now . set ( Calendar . MINUTE , 0 ) ; now . set ( Calendar . SECOND , 0 ) ; now . set ( Calendar . MILLISECOND , 0 ) ; long start = now . getTimeInMillis ( ) ; Calendar today_end = Calendar . getInstance ( ) ; today_end . set ( Calendar . HOUR_OF_DAY , 23 ) ; today_end . set ( Calendar . MINUTE , 59 ) ; today_end . set ( Calendar . SECOND , 59 ) ; while ( ! ( queue . isEmpty ( ) ) ) { boolean with_message = false ; long extra_time = 0 ; EventEntry event = queue . poll ( ) ; if ( ( event . getEndtime ( ) ) < ( Calendar . getInstance ( ) . getTimeInMillis ( ) ) ) { continue ; } Log . d ( MainActivity . TAG , ( "The<seq2seq4repair_space>new<seq2seq4repair_space>duration<seq2seq4repair_space>is<seq2seq4repair_space>" + ( event . getDuration ( ) ) ) ) ; long duration = TimeUnit . HOURS . toMillis ( event . getDuration ( ) ) ; while ( duration > 0 ) { EventEntry new_event = new EventEntry ( ) ; new_event . setCategory ( event . getCategory ( ) ) ; Calendar s = Calendar . getInstance ( ) ; s . setTimeInMillis ( start ) ; if ( ( s . get ( Calendar . HOUR_OF_DAY ) ) < 8 ) { Calendar actual_start = Calendar . getInstance ( ) ; actual_start . set ( Calendar . HOUR_OF_DAY , 8 ) ; actual_start . set ( Calendar . MINUTE , 0 ) ; actual_start . set ( Calendar . SECOND , 0 ) ; actual_start . set ( Calendar . MILLISECOND , 0 ) ; start = actual_start . getTimeInMillis ( ) ; } new_event . setStarttime ( start ) ; long end_of_day = today_end . getTimeInMillis ( ) ; if ( ( start + duration ) <= end_of_day ) { new_event . setEndtime ( ( start + duration ) ) ; start += duration ; duration = 0 ; } else { new_event . setEndtime ( end_of_day ) ; duration = duration - ( end_of_day - start ) ; Calendar tomorrow = Calendar . getInstance ( ) ; tomorrow . set ( Calendar . DAY_OF_MONTH , ( ( today_end . get ( Calendar . DAY_OF_MONTH ) ) + 1 ) ) ; tomorrow . set ( Calendar . HOUR_OF_DAY , 8 ) ; tomorrow . set ( Calendar . MINUTE , 0 ) ; tomorrow . set ( Calendar . SECOND , 0 ) ; tomorrow . set ( Calendar . MILLISECOND , 0 ) ; today_end . set ( Calendar . DAY_OF_MONTH , ( ( today_end . get ( Calendar . DAY_OF_MONTH ) ) + 1 ) ) ; start = tomorrow . getTimeInMillis ( ) ; } new_event . setDuration ( event . getDuration ( ) ) ; new_event . setContent ( event . getContent ( ) ) ; database . insertEntry ( new_event ) ; if ( ( ( event . getEndtime ( ) ) - ( new_event . getEndtime ( ) ) ) < ( TimeUnit . HOURS . toMillis ( 2 ) ) ) { SharedPreferences sharedPreferences = getSharedPreferences ( KEY_SHARED , MODE_PRIVATE ) ; SharedPreferences . Editor editor = sharedPreferences . edit ( ) ; editor . putInt ( KEY_STATE , 2 ) ;

Fix:
PriorityQueue < EventEntry > queue = new PriorityQueue < EventEntry > ( 20 , comparator ) ;