Buggy code:
public class WWinKeyBindingService { private HashMap globalActionDefIdToAction = new HashMap ( ) ; private HashMap actionSetDefIdToAction = new HashMap ( ) ; private IPropertyChangeListener propertyListener ; private KeyBindingService activeService ; private WorkbenchWindow window ; private AcceleratorMenu accMenu ; private final WWinKeyBindingService . KeyModeContributionItem statusItem = new WWinKeyBindingService . KeyModeContributionItem ( "KeyModeContribution" ) ; private VerifyListener verifyListener = new VerifyListener ( ) { public void verifyText ( VerifyEvent event ) { } } ; private void setStatusLineMessage ( KeySequence keySequence ) { } public void clear ( ) { } public void pressed ( KeyStroke keyStroke , Event event ) { } public void invoke ( String action , Event event ) { } public WWinKeyBindingService ( WorkbenchWindow workbenchWindow ) { } public void dispose ( ) { } public void registerGlobalAction ( IAction action ) { } public void registerActionSets ( IActionSet [ ] sets ) { } public HashMap getMapping ( ) { } public IWorkbenchWindow getWindow ( ) { } public void update ( IWorkbenchPart part , boolean force ) { } public String getDefinitionId ( int accelerator ) { } public void updateAccelerators ( ) { Manager keyManager = Manager . getInstance ( ) ; Machine keyMachine = keyManager . getKeyMachine ( ) ; KeySequence mode = keyMachine . getMode ( ) ; List keyStrokes = mode . getKeyStrokes ( ) ; int size = keyStrokes . size ( ) ; Map keySequenceMapForMode = keyMachine . getKeySequenceMapForMode ( ) ; SortedSet keyStrokeSetForMode = new TreeSet ( ) ; Iterator iterator = keySequenceMapForMode . keySet ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { KeySequence keySequence = ( ( KeySequence ) ( iterator . next ( ) ) ) ; if ( keySequence . isChildOf ( mode , false ) ) keyStrokeSetForMode . add ( keySequence . getKeyStrokes ( ) . get ( size ) ) ; } iterator = keyStrokeSetForMode . iterator ( ) ; int [ ] accelerators = new int [ keyStrokeSetForMode . size ( ) ] ; int i = 0 ; while ( iterator . hasNext ( ) ) { KeyStroke keyStroke = ( ( KeyStroke ) ( iterator . next ( ) ) ) ; accelerators [ ( i ++ ) ] = keyStroke . getValue ( ) ; } if ( ( ( accMenu ) == null ) || ( accMenu . isDisposed ( ) ) ) { Menu parent = window . getShell ( ) . getMenuBar ( ) ; if ( ( parent == null ) || ( ( parent . getItemCount ( ) ) < 1 ) ) return ; <START_BUG> MenuItem parentItem = parent . getItem ( 0 ) ; <END_BUG> parent = parentItem . getMenu ( ) ; accMenu = new AcceleratorMenu ( parent ) ; } if ( ( accMenu ) == null ) return ; accMenu . setAccelerators ( accelerators ) ; accMenu . addSelectionListener ( new SelectionAdapter ( ) { public void widgetSelected ( SelectionEvent selectionEvent ) { Event event = new Event ( ) ; event . item = selectionEvent . item ; event . detail = selectionEvent . detail ; event . x = selectionEvent . x ; event . y = selectionEvent . y ; event . width = selectionEvent . width ; event . height = selectionEvent . height ; event . stateMask = selectionEvent . stateMask ; event . doit = selectionEvent . doit ; event . data = selectionEvent . data ; event . display = selectionEvent . display ; event . time = selectionEvent . time ; event . widget = selectionEvent . widget ; pressed ( KeyStroke . create ( selectionEvent . detail ) , event ) ; } } ) ; if ( ( mode . getKeyStrokes ( ) . size ( ) ) == 0 ) accMenu . removeVerifyListener ( verifyListener ) ; else accMenu . addVerifyListener ( verifyListener ) ; } private static class KeyModeContributionItem extends ContributionItem { private int fixedWidth = - 1 ; private String text ; private CLabel label ; public KeyModeContributionItem ( String id ) { } public void setText ( String msg ) { } public void fill ( Composite parent ) { } } }

Fix:
MenuItem parentItem = parent . getItem ( ( ( parent . getItemCount ( ) ) - 1 ) ) ;