Buggy code:
public class IMAPFolder extends AbstractRemoteFolder { private static final Logger LOG = Logger . getLogger ( "org.columba.mail.folder.imap" ) ; private Object aktMessageUid ; private IColumbaMessage aktMessage ; private boolean mailcheck = false ; private IMAPServer store ; protected IHeaderList headerList ; protected boolean existsOnServer = true ; private IHeaderListStorage attributeStorage ; private boolean readOnly ; public boolean isReadOnly ( ) { } public IMAPFolder ( FolderItem folderItem , String path ) { } public IMAPFolder ( String name , String type , String path ) throws Exception { } public void removeFolder ( ) throws Exception { } public void setName ( String name ) throws Exception { } public IMAPServer getServer ( ) { } public IHeaderList getHeaderList ( ) throws Exception { } private synchronized void ensureFolderIsSynced ( ) throws IOException , Exception , CommandCancelledException , IMAPException { } protected ImapItem getImapItem ( ) { } protected void printStatusMessage ( String message ) { } protected void setProgress ( int progress ) { } protected void setMaximum ( int progress ) { } public void synchronizeHeaderlist ( ) throws IOException , Exception , CommandCancelledException , IMAPException { headerList = super . getHeaderList ( ) ; MailboxStatus status = getServer ( ) . getStatus ( this ) ; List localUids = extractUids ( headerList ) ; Collections . sort ( localUids ) ; int newMessages = 0 ; int largestLocalUid = - 1 ; int largestLocalUidIndex = - 1 ; int largestRemoteUid = - 1 ; printStatusMessage ( MailResourceLoader . getString ( "statusbar" , "message" , "sync_messages" ) ) ; if ( ( status . getMessages ( ) ) > 0 ) { largestRemoteUid = getServer ( ) . fetchUids ( new SequenceSet ( status . getMessages ( ) ) , this ) [ 0 ] . intValue ( ) ; printStatusMessage ( MailResourceLoader . getString ( "statusbar" , "message" , "sync_messages" ) ) ; if ( ( localUids . size ( ) ) > 0 ) { largestLocalUid = ( ( Integer ) ( localUids . get ( ( ( localUids . size ( ) ) - 1 ) ) ) ) . intValue ( ) ; int position = ( localUids . size ( ) ) - 1 ; <START_BUG> while ( ( largestLocalUidIndex == ( - 1 ) ) && ( position >= ( ( localUids . size ( ) ) - 10 ) ) ) { <END_BUG> largestLocalUidIndex = getServer ( ) . getIndex ( ( ( Integer ) ( localUids . get ( ( position -- ) ) ) ) , this ) ; } if ( largestLocalUidIndex == ( - 1 ) ) { int a ; int b ; int c ; int index ; a = 0 ; b = position ; while ( ( b - a ) > 1 ) { c = ( b - a ) > > ( 1 + a ) ; index = getServer ( ) . getIndex ( ( ( Integer ) ( localUids . get ( c ) ) ) , this ) ; if ( index == ( - 1 ) ) { b = c ; } else { a = c ; largestLocalUidIndex = index ; } } } if ( largestLocalUidIndex == ( - 1 ) ) { newMessages = status . getMessages ( ) ; largestLocalUidIndex = 0 ; } else { newMessages = ( status . getMessages ( ) ) - largestLocalUidIndex ; } } else { newMessages = status . getMessages ( ) ; largestLocalUidIndex = 0 ; } if ( ( ( ( localUids . size ( ) ) - ( status . getMessages ( ) ) ) + newMessages ) < 0 ) { IMAPFolder . LOG . severe ( ( ( "Folder<seq2seq4repair_space>" + ( getName ( ) ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>out<seq2seq4repair_space>of<seq2seq4repair_space>sync<seq2seq4repair_space>-><seq2seq4repair_space>recreating<seq2seq4repair_space>the<seq2seq4repair_space>cache!" ) ) ; getHeaderListStorage ( ) . reset ( ) ; headerList = super . getHeaderList ( ) ; newMessages = status . getMessages ( ) ; largestLocalUidIndex = 0 ; largestLocalUid = - 1 ; localUids . clear ( ) ; } IMAPFolder . LOG . fine ( ( ( "Found<seq2seq4repair_space>" + newMessages ) + "<seq2seq4repair_space>new<seq2seq4repair_space>Messages" ) ) ; if ( newMessages > 0 ) { printStatusMessage ( MailResourceLoader . getString ( "statusbar" , "message" , "fetch_new_headers" ) ) ; IMAPFlags [ ] newFlags = getServer ( ) . fetchFlagsListStartFrom ( ( largestLocalUidIndex + 1 ) , this ) ; List newUids = new ArrayList ( newFlags . length ) ; for ( int i = 0 ; i < ( newFlags . length ) ; i ++ ) { if ( ( ( ( Integer ) ( newFlags [ i ] . getUid ( ) ) ) . intValue ( ) ) <= largestLocalUid ) { IMAPFolder . LOG . severe ( "Assertion<seq2seq4repair_space>Failed<seq2seq4repair_space>:<seq2seq4repair_space>New<seq2seq4repair_space>UID<seq2seq4repair_space>is<seq2seq4repair_space>smaller" ) ; } newUids . add ( newFlags [ i ] . getUid ( ) ) ; localUids . add ( newFlags [ i ] . getUid ( ) ) ; } getServer ( ) . fetchHeaderList ( headerList , newUids , this ) ; setFlags ( newFlags ) ; for ( int i = 0 ; i < ( newFlags . length ) ; i ++ ) { fireMessageAdded ( newFlags [ i ] . getUid ( ) ) ; } IMAPRootFolder rootFolder = ( ( IMAPRootFolder ) ( getRootFolder ( ) ) ) ; AccountItem accountItem = rootFolder . getAccountItem ( ) ; ImapItem item = accountItem . getImapItem ( ) ; boolean applyFilter = item . getBooleanWithDefault ( "automatically_apply_filter" , false ) ; if ( applyFilter ) { CommandProcessor . getInstance ( ) . addOp ( new org . columba . mail . folder . command . ApplyFilterCommand ( new MailFolderCommandReference ( this , newUids . toArray ( ) ) ) ) ; } } } int deletedMessages = ( localUids . size ( ) ) - ( status . getMessages ( ) ) ;

Fix:
while ( ( ( largestLocalUidIndex == ( - 1 ) ) && ( position >= ( ( localUids . size ( ) ) - 10 ) ) ) && ( position > 0 ) ) {