Buggy code:
public class PerspectiveSwitcher { private WorkbenchWindow window ; private CBanner topBar ; private int style ; private Composite parent ; private Composite trimControl ; private Label trimSeparator ; private GridData trimLayoutData ; private boolean trimVisible = false ; private int trimOldLength = 0 ; private PerspectiveBarManager perspectiveBar ; private CoolBar perspectiveCoolBar ; private CacheWrapper perspectiveCoolBarWrapper ; private CoolItem coolItem ; private CacheWrapper toolbarWrapper ; private Menu popupMenu ; private Menu genericMenu ; private static final int INITIAL = - 1 ; private static final int TOP_RIGHT = 1 ; private static final int TOP_LEFT = 2 ; private static final int LEFT = 3 ; private static final int DEFAULT_RIGHT_X = 160 ; private int currentLocation = PerspectiveSwitcher . INITIAL ; private static final int SEPARATOR_LENGTH = 20 ; private IPreferenceStore apiPreferenceStore = PrefUtil . getAPIPreferenceStore ( ) ; private IPropertyChangeListener propertyChangeListener ; private Listener popupListener = new Listener ( ) { public void handleEvent ( Event event ) { } } ; private DisposeListener toolBarListener ; public PerspectiveSwitcher ( WorkbenchWindow window , CBanner topBar , int style ) { } private static int convertLocation ( String preference ) { } public void createControl ( Composite parent ) { } public void addPerspectiveShortcut ( IPerspectiveDescriptor perspective , WorkbenchPage workbenchPage ) { } public IContributionItem findPerspectiveShortcut ( IPerspectiveDescriptor perspective , WorkbenchPage page ) { } public void removePerspectiveShortcut ( IPerspectiveDescriptor perspective , WorkbenchPage page ) { } public void setPerspectiveBarLocation ( String preference ) { } private void showPerspectiveBar ( ) { } public void update ( boolean force ) { } public void selectPerspectiveShortcut ( IPerspectiveDescriptor perspective , WorkbenchPage page , boolean selected ) { } public void updatePerspectiveShortcut ( IPerspectiveDescriptor oldDesc , IPerspectiveDescriptor newDesc , WorkbenchPage page ) { } public PerspectiveBarManager getPerspectiveBar ( ) { } public void dispose ( ) { } private void disposeChildControls ( ) { } private void createControlForLocation ( int newLocation ) { } private void setPropertyChangeListener ( ) { } private void createControlForLeft ( ) { } private void createControlForTop ( ) { } private void setCoolItemSize ( final CoolItem coolItem ) { if ( ( currentLocation ) == ( PerspectiveSwitcher . LEFT ) ) return ; ToolBar toolbar = perspectiveBar . getControl ( ) ; if ( toolbar == null ) return ; int rowHeight = 0 ; <START_BUG> ToolItem [ ] toolItems = perspectiveBar . getControl ( ) . getItems ( ) ; <END_BUG> for ( int i = 0 ; i < ( toolItems . length ) ; i ++ ) { rowHeight = Math . max ( rowHeight , toolItems [ i ] . getBounds ( ) . height ) ; } Rectangle area = perspectiveCoolBar . getClientArea ( ) ; int rows = ( rowHeight <= 0 ) ? 1 : ( ( int ) ( Math . max ( 1 , Math . floor ( ( ( area . height ) // rowHeight ) ) ) ) ) ; if ( ( ( rows == 1 ) || ( ( ( toolbar . getStyle ( ) ) & ( SWT . WRAP ) ) == 0 ) ) || ( ( currentLocation ) == ( PerspectiveSwitcher . TOP_LEFT ) ) ) { Point p = toolbar . computeSize ( DEFAULT , DEFAULT ) ; coolItem . setSize ( coolItem . computeSize ( p . x , p . y ) ) ; return ; } Point offset = coolItem . computeSize ( 0 , 0 ) ; Point wrappedSize = toolbar . computeSize ( ( ( area . width ) - ( offset . x ) ) , DEFAULT ) ; int h = rows * rowHeight ; int w = ( ( wrappedSize . y ) <= h ) ? wrappedSize . x : ( wrappedSize . x ) + 1 ; coolItem . setSize ( coolItem . computeSize ( w , h ) ) ; } private void showPerspectiveBarPopup ( Point pt ) { } private PerspectiveBarManager createBarManager ( int direction ) { } private void updateLocationItems ( Menu parent , int newLocation ) { } private void addDockOnSubMenu ( Menu menu ) { } private void addShowTextItem ( Menu menu ) { } public void saveState ( IMemento persBarMem ) { } public void restoreState ( IMemento memento ) { } void updatePerspectiveBar ( ) { } public void updateBarParent ( ) { } }

Fix:
ToolItem [ ] toolItems = toolbar . getItems ( ) ;