Buggy code:
private MailboxInfo messageFolderInfo ; private boolean firstLogin ; boolean usingSSL ; String [ ] capabilities ; private long lastNoop ; private boolean updatesEnabled ; public IMAPServer ( ImapItem item , IMAPRootFolder root ) { } protected StatusObservable getObservable ( ) { } protected void printStatusMessage ( String message ) { } public String getDelimiter ( ) throws IOException , CommandCancelledException , IMAPException { } public void logout ( ) throws Exception { } private void openConnection ( ) throws IOException , CommandCancelledException , IMAPException { } public List checkSupportedAuthenticationMethods ( ) throws IOException { } private String [ ] getCapas ( String command ) throws IOException { } public boolean isSupported ( String command ) throws IOException { } private void fetchCapas ( ) throws IOException { } private int getLoginMethod ( ) throws IOException , CommandCancelledException { } private void login ( ) throws IOException , CommandCancelledException , IMAPException { } protected void ensureSelectedState ( IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public MailboxStatus getStatus ( IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } protected String fetchDelimiter ( ) throws IOException , CommandCancelledException , IMAPException { } public ListInfo [ ] list ( String reference , String pattern ) throws Exception { } public Integer append ( InputStream messageSource , IMAPFolder folder ) throws Exception { } public Integer append ( InputStream messageSource , IMAPFlags flags , IMAPFolder folder ) throws Exception { } public void createMailbox ( String mailboxName , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public void deleteFolder ( String path ) throws Exception { } public void renameFolder ( String oldMailboxName , String newMailboxName ) throws IOException , CommandCancelledException , IMAPException { } public void subscribeFolder ( String mailboxName ) throws IOException , CommandCancelledException , IMAPException { } public void unsubscribeFolder ( String mailboxName ) throws IOException , CommandCancelledException , IMAPException { } public void expunge ( IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public Integer [ ] copy ( IMAPFolder destFolder , Object [ ] uids , IMAPFolder folder ) throws Exception { } public Integer [ ] fetchUids ( SequenceSet set , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } private SequenceSet [ ] divide ( SequenceSet in ) { } public IMAPFlags [ ] fetchFlagsListStartFrom ( int startIdx , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { try { StatusObservable observable = getObservable ( ) ; ensureSelectedState ( folder ) ; if ( ( ( messageFolderInfo . getExists ( ) ) - startIdx ) > 0 ) { SequenceSet set = new SequenceSet ( ) ; set . addRightOpen ( startIdx ) ; SequenceSet [ ] packs = divide ( set ) ; if ( observable != null ) { observable . setCurrent ( 0 ) ; observable . setMax ( set . getLength ( messageFolderInfo . getExists ( ) ) ) ; } List allResults = new ArrayList ( packs . length ) ; int pos = 0 ; for ( int i = 0 ; i < ( packs . length ) ; i ++ ) { IMAPFlags [ ] r = protocol . fetchFlags ( packs [ i ] ) ; pos += r . length ; allResults . add ( r ) ; if ( observable != null ) { observable . setCurrent ( pos ) ; } } IMAPFlags [ ] result = new IMAPFlags [ pos ] ; Iterator it = allResults . iterator ( ) ; pos = 0 ; while ( it . hasNext ( ) ) { IMAPFlags [ ] r = ( ( IMAPFlags [ ] ) ( it . next ( ) ) ) ; <START_BUG> System . arraycopy ( result , 0 , r , pos , r . length ) ; <END_BUG> pos += r . length ; } return result ; } else { return new IMAPFlags [ 0 ] ; } } catch ( IMAPDisconnectedException e ) { return fetchFlagsListStartFrom ( startIdx , folder ) ; } } public NamespaceCollection fetchNamespaces ( ) throws IOException , CommandCancelledException , IMAPException { } private ColumbaHeader parseMessage ( String headerString ) { } public void fetchHeaderList ( IHeaderList headerList , List list , IMAPFolder folder ) throws Exception { } private void doFetchHeaderList ( IHeaderList headerList , List list ) throws IOException , IMAPException { } protected void ensureConnectedState ( ) throws IOException , CommandCancelledException , IMAPException { } protected void ensureLoginState ( ) throws IOException , CommandCancelledException , IMAPException { } public MimeTree getMimeTree ( Object uid , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public InputStream getMimePartBodyStream ( Object uid , Integer [ ] address , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public Header getHeaders ( Object uid , String [ ] keys , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public Header getAllHeaders ( Object uid , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public InputStream getMimePartSourceStream ( Object uid , Integer [ ] address , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public InputStream getMessageSourceStream ( Object uid , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public void markMessage ( Object [ ] uids , int variant , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public void setFlags ( Object [ ] uids , IMAPFlags flags , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public List search ( Object [ ] uids , FilterRule filterRule , IMAPFolder folder ) throws Exception { } public int getIndex ( Integer uid , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { } public Integer [ ] search ( SearchKey key , IMAPFolder folder ) throws IOException , CommandCancelledException , IMAPException { }

Fix:
System . arraycopy ( r , 0 , result , pos , r . length ) ;