Buggy code:
public class CoolBarManager extends ContributionManager implements IToolBarManager { private int style = SWT . NONE ; private CoolBar coolBar = null ; private MenuManager chevronMenuManager ; private MenuManager coolBarMenuManager = new MenuManager ( ) ; private Menu coolBarMenu = null ; private boolean rememberPositions = false ; private ArrayList rememberedPositions = new ArrayList ( ) ; private class RestoreItemData { CoolItemPosition savedPosition ; String beforeItemId ; String afterItemId ; int beforeIndex = - 1 ; int afterIndex = - 1 ; RestoreItemData ( ) { } } public CoolBarManager ( ) { } public CoolBarManager ( int style ) { } public void add ( IAction action ) { } public void add ( IContributionItem item ) { } public void addToMenu ( ActionContributionItem item ) { } private void addToGroup ( String itemId , IContributionItem item , boolean append ) { } private boolean coolBarExist ( ) { } CoolBar createControl ( Composite parent ) { } private CoolItem createCoolItem ( CoolBarContributionItem cbItem , ToolBar toolBar ) { } private CoolItem createNewCoolItem ( CoolBarContributionItem cbItem , ToolBar toolBar ) { } private CoolItem createRememberedCoolItem ( CoolBarContributionItem cbItem , ToolBar toolBar , CoolItemPosition position ) { } private void dispose ( CoolBarContributionItem cbItem ) { } private void dispose ( CoolItem coolItem ) { } void dispose ( ) { } private CoolItem findCoolItem ( CoolBarContributionItem item ) { } CoolBarContributionItem findSubId ( String id ) { } private ArrayList getContributionIds ( ) { } private ArrayList getCoolItemIds ( ) { } Menu getCoolBarMenu ( ) { } CoolBar getControl ( ) { } private int getInsertAfterIndex ( CoolBarContributionItem coolBarItem ) { } private int getInsertBeforeIndex ( CoolBarContributionItem coolBarItem ) { } private CoolBarLayout getLayout ( ) { } private CoolBarManager . RestoreItemData getRestoreData ( CoolBarContributionItem cbItem , CoolItemPosition position ) { } private CoolItemPosition getRememberedPosition ( String cbItemId ) { } int getStyle ( ) { } private void handleChevron ( SelectionEvent event ) { } public void insertAfter ( String id , IAction action ) { } public void insertAfter ( String id , IContributionItem item ) { } public void insertBefore ( String id , IAction action ) { } public void insertBefore ( String id , IContributionItem item ) { } boolean isLayoutLocked ( ) { } void lockLayout ( boolean value ) { } private void positionAdded ( CoolItemPosition position ) { } private void redoLayout ( ) { } private void resetLayout ( ) { } public IContributionItem remove ( IContributionItem item ) { } private void relayout ( ) { } private CoolItemPosition rememberPositionFor ( String cbItemId , CoolBarLayout layout ) { } void saveLayoutFor ( Perspective perspective ) { } void setLayoutFor ( Perspective perspective ) { } private void setLayout ( CoolBarLayout layout ) { } private void setLayoutTo ( CoolBarLayout layout ) { } private void setSizeFor ( CoolItem coolItem ) { } private void setSizeFor ( CoolItem coolItem , int coolWidth ) { } public void update ( boolean force ) { if ( ( isDirty ( ) ) || force ) { if ( coolBarExist ( ) ) { boolean useRedraw = false ; CoolBarLayout layout = getLayout ( ) ; IContributionItem [ ] items = getItems ( ) ; ArrayList cbItemsToRemove = new ArrayList ( items . length ) ; for ( int i = 0 ; i < ( items . length ) ; i ++ ) { CoolBarContributionItem cbItem = ( ( CoolBarContributionItem ) ( items [ i ] ) ) ; <START_BUG> if ( ( cbItem . getItems ( ) . length ) == 0 ) { <END_BUG> CoolItem coolItem = findCoolItem ( cbItem ) ; if ( ( ! useRedraw ) && ( coolItem != null ) ) { int visualIndex = coolBar . indexOf ( coolItem ) ; if ( layout . isOnRowAlone ( visualIndex ) ) { useRedraw = true ; } } cbItemsToRemove . add ( cbItem ) ; } } CoolItem [ ] coolItems = coolBar . getItems ( ) ; ArrayList coolItemsToRemove = new ArrayList ( coolItems . length ) ; for ( int i = 0 ; i < ( coolItems . length ) ; i ++ ) { CoolItem coolItem = coolItems [ i ] ; CoolBarContributionItem cbItem = ( ( CoolBarContributionItem ) ( coolItem . getData ( ) ) ) ; if ( ( ( cbItem != null ) && ( ! ( cbItem . isVisible ( ) ) ) ) && ( ! ( cbItemsToRemove . contains ( cbItem ) ) ) ) { if ( ! useRedraw ) { int visualIndex = coolBar . indexOf ( coolItem ) ; if ( layout . isOnRowAlone ( visualIndex ) ) { useRedraw = true ; } } coolItemsToRemove . add ( coolItem ) ; } } if ( ( ! useRedraw ) && ( ( ( cbItemsToRemove . size ( ) ) + ( coolItemsToRemove . size ( ) ) ) > 2 ) ) { useRedraw = true ; } if ( useRedraw ) coolBar . setRedraw ( false ) ; for ( Iterator e = cbItemsToRemove . iterator ( ) ; e . hasNext ( ) ; ) { CoolBarContributionItem cbItem = ( ( CoolBarContributionItem ) ( e . next ( ) ) ) ; dispose ( cbItem ) ; } for ( Iterator e = coolItemsToRemove . iterator ( ) ; e . hasNext ( ) ; ) { CoolItem coolItem = ( ( CoolItem ) ( e . next ( ) ) ) ; ToolBar tBar = ( ( ToolBar ) ( coolItem . getControl ( ) ) ) ; tBar . setVisible ( false ) ; dispose ( coolItem ) ; } ArrayList coolItemIds = getCoolItemIds ( ) ; items = getItems ( ) ; boolean changed = false ; boolean relock = false ; for ( int i = 0 ; i < ( items . length ) ;

Fix:
if ( cbItem . isEmpty ( ) ) {