Buggy code:
public void updateActionBars ( ) { } public void clearGlobalActionHandlers ( ) { } public IAction getGlobalActionHandler ( String actionId ) { } public void registerGlobalAction ( IAction action ) { } public void dispose ( ) { } public final IServiceLocator getServiceLocator ( ) { } public IToolBarContributionItem createToolBarContributionItem ( IToolBarManager toolBarManager , String id ) { } public IToolBarManager createToolBarManager ( ) { } } public CustomizePerspectiveDialog ( IWorkbenchWindowConfigurer configurer , Perspective persp ) { } protected void configureShell ( Shell shell ) { } protected Control createDialogArea ( Composite parent ) { } private Composite createShortCutsPage ( Composite parent ) { } private Composite createActionSetAvailabilityPage ( Composite parent ) { } private Composite createMenuVisibilityPage ( Composite parent ) { } private Composite createToolBarVisibilityPage ( Composite parent ) { } private TableViewer initActionSetViewer ( Composite parent ) { } private CheckboxTreeViewer initStructureViewer ( Composite parent , ICheckStateListener checkStateListener , ViewerFilter filter ) { } private static Composite createItemStructureGroup ( final Composite composite , String labelText ) { } private static Composite createActionSetGroup ( final Composite composite ) { } private void setSelectionOn ( Viewer viewer , final Object selected ) { } private static boolean includeInSetStructure ( CustomizePerspectiveDialog . DisplayItem item , CustomizePerspectiveDialog . ActionSet set ) { } private static boolean isAvailable ( CustomizePerspectiveDialog . DisplayItem item ) { } private static boolean isEffectivelyAvailable ( CustomizePerspectiveDialog . DisplayItem item , ViewerFilter filter ) { } private static void collectDescendantCommandGroups ( Collection collection , CustomizePerspectiveDialog . DisplayItem item , ViewerFilter filter ) { } private Binding [ ] getKeyBindings ( CustomizePerspectiveDialog . DisplayItem item ) { } private String keyBindingsAsString ( Binding [ ] bindings ) { } private void actionSetAvailabilityChanged ( ) { } private void initializeActionSetInput ( ) { } private void initializeIcons ( ) { } private void initializeNewWizardsMenu ( CustomizePerspectiveDialog . DisplayItem menu , CustomizePerspectiveDialog . Category parentCategory , IWizardCategory element , List activeIds ) { } private void initializeNewWizardsMenu ( CustomizePerspectiveDialog . DisplayItem menu ) { } private void initializePerspectivesMenu ( CustomizePerspectiveDialog . DisplayItem menu ) { } private void initializeViewsMenu ( CustomizePerspectiveDialog . DisplayItem menu ) { } private void loadMenuAndToolbarStructure ( ) { } private PluginActionSet buildMenusAndToolbarsFor ( CustomizePerspectiveDialog . CustomizeActionBars customizeActionBars , ActionSetDescriptor actionSetDesc ) { } private static String getCommandID ( CustomizePerspectiveDialog . DisplayItem item ) { } public static String getIDFromIContributionItem ( Object object ) { } private static String getDescription ( Object object ) { } private static String getDescription ( IContributionItem item ) { } private static String getParamID ( CustomizePerspectiveDialog . DisplayItem object ) { } private static boolean isNewWizard ( CustomizePerspectiveDialog . DisplayItem item ) { } private static boolean isShowPerspective ( CustomizePerspectiveDialog . DisplayItem item ) { } private static boolean isShowView ( CustomizePerspectiveDialog . DisplayItem item ) { } private static String getActionSetID ( IContributionItem item ) { } private static void makeAllContributionsVisible ( IContributionManager manager ) { } private static void makeContributionVisible ( IContributionItem item ) { } private CustomizePerspectiveDialog . DisplayItem createMenuStructure ( Menu menu ) { } private void createMenuEntries ( Menu menu , CustomizePerspectiveDialog . DisplayItem parent , boolean trackDynamics ) { } private boolean getMenuItemIsVisible ( CustomizePerspectiveDialog . DisplayItem item ) { } private boolean getToolbarItemIsVisible ( CustomizePerspectiveDialog . DisplayItem item ) { } private void updateCategoryAndParents ( StructuredViewer viewer , CustomizePerspectiveDialog . Category category ) { } private CustomizePerspectiveDialog . DisplayItem createToolBarStructure ( CoolBar coolbar ) { } private void createToolbarEntries ( CoolBar coolbar , CustomizePerspectiveDialog . DisplayItem parent ) { } private void createToolbarEntries ( ToolItem [ ] toolitems , CustomizePerspectiveDialog . DisplayItem parent ) { } private boolean showShortcutTab ( ) { } private ArrayList getVisibleIDs ( TreeItem root ) { } private void getChangedIds ( CustomizePerspectiveDialog . DisplayItem item , List invisible , List visible ) { } private boolean updateHiddenElements ( CustomizePerspectiveDialog . DisplayItem items , Collection currentHidden ) { } protected void okPressed ( ) { if ( showShortcutTab ( ) ) { perspective . setNewWizardActionIds ( getVisibleIDs ( wizards ) ) ; perspective . setPerspectiveActionIds ( getVisibleIDs ( perspectives ) ) ; perspective . setShowViewActionIds ( getVisibleIDs ( views ) ) ; } boolean requiresUpdate = false ; ArrayList toAdd = new ArrayList ( ) ; ArrayList toRemove = new ArrayList ( ) ; for ( Iterator i = actionSets . iterator ( ) ; i . hasNext ( ) ; ) { CustomizePerspectiveDialog . ActionSet actionSet = ( ( CustomizePerspectiveDialog . ActionSet ) ( i . next ( ) ) ) ; if ( ! ( actionSet . wasChanged ( ) ) ) continue ; requiresUpdate = true ; if ( actionSet . isActive ( ) ) { toAdd . add ( actionSet . descriptor ) ; } else { toRemove . add ( actionSet . descriptor ) ; } } perspective . turnOnActionSets ( ( ( IActionSetDescriptor [ ] ) ( toAdd . toArray ( new IActionSetDescriptor [ toAdd . size ( ) ] ) ) ) ) ; <START_BUG> perspective . turnOffActionSets ( ( ( IActionSetDescriptor [ ] ) ( toRemove . toArray ( new IActionSetDescriptor [ toAdd . size ( ) ] ) ) ) ) ; <END_BUG> requiresUpdate |= updateHiddenElements ( menuItems , perspective . getHiddenMenuItems ( ) ) ; requiresUpdate |= updateHiddenElements ( toolBarItems , perspective . getHiddenToolbarItems ( ) ) ; if ( requiresUpdate ) { perspective . updateActionBars ( ) ; } super . okPressed ( ) ; } public boolean close ( ) { } private String removeShortcut ( String label ) { } protected boolean applyDialogFont ( ) { } protected boolean isResizable ( ) { } private void viewActionSet ( final CustomizePerspectiveDialog . DisplayItem item ) { } private void viewActionSet ( final CustomizePerspectiveDialog . ActionSet actionSet ) { } private static int getLeafStates ( TreeItem item , ITreeContentProvider provider , ViewerFilter filter ) { } private static void setAllLeafs ( CustomizePerspectiveDialog . DisplayItem item , boolean value , ITreeContentProvider provider , ViewerFilter filter ) { } }

Fix:
perspective . turnOffActionSets ( ( ( IActionSetDescriptor [ ] ) ( toRemove . toArray ( new IActionSetDescriptor [ toRemove . size ( ) ] ) ) ) ) ;