Buggy code:
public class AddActivity extends ListActivity { private static final String TAG = "AddActivity.TAG" ; private EventEntry entry ; private EventEntryDatasource datasource ; public Calendar endTime = Calendar . getInstance ( ) ; @ Override protected void onCreate ( Bundle savedInstanceState ) { } @ Override protected void onListItemClick ( ListView l , View v , int position , long id ) { } public void onSaveClicked ( View v ) { } public void onCancelClicked ( View v ) { } public void setTitle ( String title ) { } public void setCategory ( String comment ) { } public void setEventType ( int type ) { } public void setStopDate ( int year , int month , int day ) { } public void setStopTime ( int year , int month , int day , int hour , int minute ) { } public void setDetail ( String str ) { } public void setDuration ( String time ) { } private void arrangeTime ( ) { mergeDataBase ( ) ; ArrayList < EventEntry > en = datasource . fetchEntries ( ) ; Log . d ( AddActivity . 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 ( ) ; datasource . 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 ; } 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 ( ) ) ; datasource . 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 ) ; editor . putString ( KEY_REASON , ( ( "Course<seq2seq4repair_space>" + ( new_event . getCategory ( ) ) ) + "<seq2seq4repair_space>may<seq2seq4repair_space>miss<seq2seq4repair_space>the<seq2seq4repair_space>deadline" ) ) ; editor . commit ( ) ; with_message = true ; } extra_time += ( event . getEndtime ( ) ) - ( new_event . getEndtime ( ) ) ; } if ( ( ( ! with_message ) && ( extra_time >= ( TimeUnit . HOURS . toMillis ( 2 ) ) ) ) && ( extra_time <= ( TimeUnit . HOURS . toMillis ( 24 ) ) ) ) { SharedPreferences sharedPreferences = getSharedPreferences ( KEY_SHARED , MODE_PRIVATE ) ; SharedPreferences . Editor editor = sharedPreferences . edit ( ) ; editor . putInt ( KEY_STATE , 1 ) ; editor . putString ( KEY_REASON , "You<seq2seq4repair_space>have<seq2seq4repair_space>enough<seq2seq4repair_space>time<seq2seq4repair_space>to<seq2seq4repair_space>finish<seq2seq4repair_space>all<seq2seq4repair_space>your<seq2seq4repair_space>work." ) ; editor . commit ( ) ; }

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