Buggy code:
public class FolderTreeDnd implements Autoscroll , DragGestureListener , DragSourceListener { private TreeController treeController ; private JTree tree ; private Folder sourceFolder ; private DragSource dragSource ; private TreePath _pathSource ; private BufferedImage _imgGhost ; private Point _ptOffset = new Point ( ) ; public FolderTreeDnd ( TreeController c ) { } public void dragGestureRecognized ( DragGestureEvent e ) { } public void dragDropEnd ( DragSourceDropEvent e ) { } public void dragExit ( DragSourceEvent e ) { } public void dragEnter ( DragSourceDragEvent e ) { } public void dragOver ( DragSourceDragEvent e ) { } public void dropActionChanged ( DragSourceDragEvent e ) { } class CDropTargetListener implements DropTargetListener { private TreePath _pathLast = null ; private Rectangle2D _raCueLine = new Rectangle2D . Float ( ) ; private Rectangle2D _raGhost = new Rectangle2D . Float ( ) ; private Color _colorCueLine ; private Point _ptLast = new Point ( ) ; private Timer _timerHover ; private int _nLeftRight = 0 ; private BufferedImage _imgRight = new CArrowImage ( 15 , 15 , CArrowImage . ARROW_RIGHT ) ; private BufferedImage _imgLeft = new CArrowImage ( 15 , 15 , CArrowImage . ARROW_LEFT ) ; private int _nShift = 0 ; public CDropTargetListener ( ) { } public void dragEnter ( DropTargetDragEvent e ) { } public void dragExit ( DropTargetEvent e ) { } public void dragOver ( DropTargetDragEvent e ) { } public void dropActionChanged ( DropTargetDragEvent e ) { } public void drop ( DropTargetDropEvent e ) { _timerHover . stop ( ) ; if ( ! ( isDropAcceptable ( e ) ) ) { e . rejectDrop ( ) ; return ; } e . acceptDrop ( e . getDropAction ( ) ) ; Transferable transferable = e . getTransferable ( ) ; DataFlavor [ ] flavors = transferable . getTransferDataFlavors ( ) ; for ( int i = 0 ; i < ( flavors . length ) ; i ++ ) { DataFlavor flavor = flavors [ i ] ; if ( flavor . equals ( DataFlavor . stringFlavor ) ) { System . out . println ( "message<seq2seq4repair_space>dnd" ) ; Point pt = e . getLocation ( ) ; TreePath pathTarget = tree . getClosestPathForLocation ( pt . x , pt . y ) ; Folder target = ( ( Folder ) ( pathTarget . getLastPathComponent ( ) ) ) ; <START_BUG> FolderCommandReference [ ] selection = ( ( FolderCommandReference [ ] ) ( treeController . getMailFrameController ( ) . getSelectionManager ( ) . getSelection ( "mail.headertable" ) ) ) ; <END_BUG> if ( target != ( selection [ 0 ] . getFolder ( ) ) ) { FolderCommandReference [ ] result = new FolderCommandReference [ 2 ] ; result [ 0 ] = selection [ 0 ] ; result [ 1 ] = new FolderCommandReference ( target ) ; if ( ( e . getDropAction ( ) ) == 1 ) { log . debug ( "copy<seq2seq4repair_space>action" ) ; CopyMessageCommand c = new CopyMessageCommand ( result ) ; processor . addOp ( c ) ; e . dropComplete ( true ) ; } else if ( ( e . getDropAction ( ) ) == 2 ) { System . out . println ( "move<seq2seq4repair_space>action" ) ; MoveMessageCommand c = new MoveMessageCommand ( result ) ; processor . addOp ( c ) ; e . dropComplete ( true ) ; } else { log . debug ( "drop<seq2seq4repair_space>action<seq2seq4repair_space>not<seq2seq4repair_space>supported" ) ; break ; } } else { JOptionPane . showMessageDialog ( null , "Invalid<seq2seq4repair_space>Folder!" ) ; break ; } } else if ( flavor . isMimeTypeEqual ( DataFlavor . javaJVMLocalObjectMimeType ) ) { try { Point pt = e . getLocation ( ) ; TreePath pathTarget = tree . getClosestPathForLocation ( pt . x , pt . y ) ; TreePath pathSource = ( ( TreePath ) ( transferable . getTransferData ( flavor ) ) ) ; System . out . println ( ( "DROPPING:<seq2seq4repair_space>" + ( pathSource . getLastPathComponent ( ) ) ) ) ; TreeModel model = treeController . getModel ( ) ; TreePath pathNewChild = null ; Folder source = ( ( Folder ) ( pathSource . getLastPathComponent ( ) ) ) ; FolderItem item = source . getFolderItem ( ) ; Folder dest = ( ( Folder ) ( pathTarget . getLastPathComponent ( ) ) ) ; Rectangle raPath = tree . getPathBounds ( pathTarget ) ; Rectangle raPath2 = ( ( Rectangle ) ( raPath . clone ( ) ) ) ; raPath2 . height = raPath2 . height ; if ( raPath2 . contains ( pt . x , pt . y ) ) { Folder sourceParent = ( ( Folder ) ( source . getParent ( ) ) ) ; Folder destParent = ( ( Folder ) ( dest . getParent ( ) ) ) ; if ( sourceParent . equals ( dest ) ) { JOptionPane . showMessageDialog ( null , "No<seq2seq4repair_space>valid<seq2seq4repair_space>folder<seq2seq4repair_space>for<seq2seq4repair_space>drop!" ) ; } else { System . out . println ( ( "------------><seq2seq4repair_space>append<seq2seq4repair_space>at=" + ( dest . getName ( ) ) ) ) ; dest . append ( source ) ; treeModel . nodeStructureChanged ( destParent ) ; } } else { Folder destParent = ( ( Folder ) ( dest . getParent ( ) ) ) ; int count = destParent . getChildCount ( ) ; int destIndex = destParent . getIndex ( dest ) ; Folder sourceParent = ( ( Folder ) ( source . getParent ( ) ) ) ; int sourceIndex = sourceParent . getIndex ( source ) ; log . debug ( ( "source=" + ( source . getName ( ) ) ) ) ; log . debug ( ( "dest=" + ( dest . getName ( ) ) ) ) ; if ( source . getParent ( ) . equals ( dest ) ) { JOptionPane . showMessageDialog ( null , "No<seq2seq4repair_space>valid<seq2seq4repair_space>folder<seq2seq4repair_space>for<seq2seq4repair_space>drop!" ) ; }

Fix:
FolderCommandReference [ ] selection = ( ( FolderCommandReference [ ] ) ( treeController . getMailFrameController ( ) . getSelectionManager ( ) . getSelection ( "mail.table" ) ) ) ;