Buggy code:
private PerspectiveHistory perspHistory ; private boolean runEventLoop ; private boolean isStarting = true ; private boolean isClosing = false ; private boolean autoBuild ; private Object returnCode ; private WorkbenchConfigurationInfo configurationInfo ; private ListenerList windowListeners = new ListenerList ( ) ; private String [ ] commandLineArgs ; private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener ( ) { public void propertyChange ( PropertyChangeEvent event ) { } } ; private static final String [ ] VERSION_STRING = new String [ ] { "0.046" , "2.0" } ; private static final String DEFAULT_WORKBENCH_STATE_FILENAME = "workbench.xml" ; private static final int RESTORE_CODE_OK = 0 ; private static final int RESTORE_CODE_RESET = 1 ; private static final int RESTORE_CODE_EXIT = 2 ; protected static final String WELCOME_EDITOR_ID = "org.eclipse.ui.internal.dialogs.WelcomeEditor" ; public Workbench ( ) { } private ICommandHandlerServiceListener commandHandlerServiceListener = new ICommandHandlerServiceListener ( ) { public void commandHandlerServiceChanged ( ICommandHandlerServiceEvent commandHandlerServiceEvent ) { } } ; private IContextActivationServiceListener contextActivationServiceListener = new IContextActivationServiceListener ( ) { public void contextActivationServiceChanged ( IContextActivationServiceEvent contextActivationServiceEvent ) { } } ; private IInternalPerspectiveListener internalPerspectiveListener = new IInternalPerspectiveListener ( ) { public void perspectiveActivated ( IWorkbenchPage workbenchPage , IPerspectiveDescriptor perspectiveDescriptor ) { } public void perspectiveChanged ( IWorkbenchPage workbenchPage , IPerspectiveDescriptor perspectiveDescriptor , String changeId ) { } public void perspectiveClosed ( IWorkbenchPage page , IPerspectiveDescriptor perspective ) { } public void perspectiveOpened ( IWorkbenchPage page , IPerspectiveDescriptor perspective ) { } } ; private IPageListener pageListener = new IPageListener ( ) { public void pageActivated ( IWorkbenchPage workbenchPage ) { } public void pageClosed ( IWorkbenchPage workbenchPage ) { } public void pageOpened ( IWorkbenchPage workbenchPage ) { } } ; private IPartListener partListener = new IPartListener ( ) { public void partActivated ( IWorkbenchPart workbenchPart ) { } public void partBroughtToTop ( IWorkbenchPart workbenchPart ) { } public void partClosed ( IWorkbenchPart workbenchPart ) { } public void partDeactivated ( IWorkbenchPart workbenchPart ) { } public void partOpened ( IWorkbenchPart workbenchPart ) { } } ; private IWindowListener windowListener = new IWindowListener ( ) { public void windowActivated ( IWorkbenchWindow workbenchWindow ) { } public void windowClosed ( IWorkbenchWindow workbenchWindow ) { } public void windowDeactivated ( IWorkbenchWindow workbenchWindow ) { } public void windowOpened ( IWorkbenchWindow workbenchWindow ) { } } ; private IWorkbenchWindow activeWorkbenchWindow ; private ICommandHandlerService activeWorkbenchWindowCommandHandlerService ; private IContextActivationService activeWorkbenchWindowContextActivationService ; private IWorkbenchPage activeWorkbenchPage ; private ICommandHandlerService activeWorkbenchPageCommandHandlerService ; private IContextActivationService activeWorkbenchPageContextActivationService ; private IWorkbenchPart activeWorkbenchPart ; private ICommandHandlerService activeWorkbenchPartCommandHandlerService ; private IContextActivationService activeWorkbenchPartContextActivationService ; private ICommandHandlerService commandHandlerService ; private ICommandManager commandManager ; private IContextActivationService contextActivationService ; private IContextManager contextManager ; public ICommandHandlerService getCommandHandlerService ( ) { } public ICommandManager getCommandManager ( ) { } public IContextActivationService getContextActivationService ( ) { } public IContextManager getContextManager ( ) { } private void initializeCommandsAndContexts ( ) { } private void updateCommandsAndContexts ( ) { IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow ( ) ; <START_BUG> if ( ! ( activeWorkbenchWindow instanceof WorkbenchWindow ) ) <END_BUG> activeWorkbenchWindow = null ; ICommandHandlerService activeWorkbenchWindowCommandHandlerService = ( activeWorkbenchWindow != null ) ? ( ( WorkbenchWindow ) ( activeWorkbenchWindow ) ) . getCommandHandlerService ( ) : null ; IContextActivationService activeWorkbenchWindowContextActivationService = ( activeWorkbenchWindow != null ) ? ( ( WorkbenchWindow ) ( activeWorkbenchWindow ) ) . getContextActivationService ( ) : null ; IWorkbenchPage activeWorkbenchPage = ( activeWorkbenchWindow != null ) ? activeWorkbenchWindow . getActivePage ( ) : null ; ICommandHandlerService activeWorkbenchPageCommandHandlerService = ( activeWorkbenchPage != null ) ? ( ( WorkbenchPage ) ( activeWorkbenchPage ) ) . getCommandHandlerService ( ) : null ; IContextActivationService activeWorkbenchPageContextActivationService = ( activeWorkbenchPage != null ) ? ( ( WorkbenchPage ) ( activeWorkbenchPage ) ) . getContextActivationService ( ) : null ; IPartService activePartService = ( activeWorkbenchWindow != null ) ? activeWorkbenchWindow . getPartService ( ) : null ; IWorkbenchPart activeWorkbenchPart = ( activePartService != null ) ? activePartService . getActivePart ( ) : null ; IWorkbenchPartSite activeWorkbenchPartSite = ( activeWorkbenchPart != null ) ? activeWorkbenchPart . getSite ( ) : null ; ICommandHandlerService activeWorkbenchPartCommandHandlerService = ( activeWorkbenchPartSite != null ) ? ( ( PartSite ) ( activeWorkbenchPartSite ) ) . getCommandHandlerService ( ) : null ; IContextActivationService activeWorkbenchPartContextActivationService = ( activeWorkbenchPartSite != null ) ? ( ( PartSite ) ( activeWorkbenchPartSite ) ) . getContextActivationService ( ) : null ; if ( activeWorkbenchWindow != ( this . activeWorkbenchWindow ) ) { if ( ( this . activeWorkbenchWindow ) != null ) { this . activeWorkbenchWindow . removePageListener ( pageListener ) ; this . activeWorkbenchWindow . getPartService ( ) . removePartListener ( partListener ) ; ( ( WorkbenchWindow ) ( this . activeWorkbenchWindow ) ) . getPerspectiveService ( ) . removePerspectiveListener ( internalPerspectiveListener ) ; } this . activeWorkbenchWindow = activeWorkbenchWindow ; if ( ( this . activeWorkbenchWindow ) != null ) { this . activeWorkbenchWindow . addPageListener ( pageListener ) ; this . activeWorkbenchWindow . getPartService ( ) . addPartListener ( partListener ) ; ( ( WorkbenchWindow ) ( this . activeWorkbenchWindow ) ) . getPerspectiveService ( ) . addPerspectiveListener ( internalPerspectiveListener ) ; } } if ( activeWorkbenchWindowCommandHandlerService != ( this . activeWorkbenchWindowCommandHandlerService ) ) { if ( ( this . activeWorkbenchWindowCommandHandlerService ) != null ) this . activeWorkbenchWindowCommandHandlerService . removeCommandHandlerServiceListener ( commandHandlerServiceListener ) ; this . activeWorkbenchWindow = activeWorkbenchWindow ; this . activeWorkbenchWindowCommandHandlerService = activeWorkbenchWindowCommandHandlerService ; if ( ( this . activeWorkbenchWindowCommandHandlerService ) != null ) this . activeWorkbenchWindowCommandHandlerService . addCommandHandlerServiceListener ( commandHandlerServiceListener ) ; } if ( activeWorkbenchPageCommandHandlerService != ( this . activeWorkbenchPageCommandHandlerService ) ) { if ( ( this . activeWorkbenchPageCommandHandlerService ) != null ) this . activeWorkbenchPageCommandHandlerService . removeCommandHandlerServiceListener ( commandHandlerServiceListener ) ; this . activeWorkbenchPage = activeWorkbenchPage ; this . activeWorkbenchPageCommandHandlerService = activeWorkbenchPageCommandHandlerService ; if ( ( this . activeWorkbenchPageCommandHandlerService ) != null ) this . activeWorkbenchPageCommandHandlerService . addCommandHandlerServiceListener ( commandHandlerServiceListener ) ; } if ( activeWorkbenchPartCommandHandlerService != ( this . activeWorkbenchPartCommandHandlerService ) ) { if ( ( this . activeWorkbenchPartCommandHandlerService ) != null ) this . activeWorkbenchPartCommandHandlerService . removeCommandHandlerServiceListener ( commandHandlerServiceListener ) ; this . activeWorkbenchPart = activeWorkbenchPart ; this . activeWorkbenchPartCommandHandlerService = activeWorkbenchPartCommandHandlerService ;

Fix:
if ( ( activeWorkbenchWindow != null ) && ( ! ( activeWorkbenchWindow instanceof WorkbenchWindow ) ) )