Bug 320158 [Compatibility] NPEs when closing and reopening perspective
1. Open a fresh e4 workbench 2. Close the Java perspective via the menu (Window > ...) 3. Open the Java perspective again via the perspective switcher Result: Several ERRORs and stack traces on the console (in the host Eclipse): Note: The NPEs do not occur when the perspective is closed via the context menu of the perspective switcher.
bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java
import org.eclipse.ui.internal.IPreferenceConstants;
import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
import org.eclipse.ui.internal.WorkbenchImages;
import org.eclipse.ui.internal.dialogs.SelectPerspectiveDialog;
import org.eclipse.ui.internal.registry.PerspectiveDescriptor;
import org.eclipse.ui.internal.util.PrefUtil;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
public class PerspectiveSwitcher {
	public static final String PERSPECTIVE_SWITCHER_ID = "org.eclipse.e4.ui.PerspectiveSwitcher"; 
	@Inject
	protected IEventBroker eventBroker;
	@Inject
	EModelService modelService;
	@Inject
	private MWindow window;
	private MToolControl psME;
	private ToolBar psTB;
	private Composite comp;
	private Image backgroundImage;
	Color borderColor;
	Control toolParent;
	private EventHandler selectionHandler = new EventHandler() {
		public void handleEvent(Event event) {
			if (psTB.isDisposed()) {
				return;
			}
			MUIElement changedElement = (MUIElement) event.getProperty(UIEvents.EventTags.ELEMENT);
			if (psME == null || !(changedElement instanceof MPerspectiveStack))
				return;