Project: Eclipse_Platform_UI
Bug 396909 SWT IFocusService prone to cause NPE's during shutdown
Reported: 2012-12-19 06:22:51 | Status: resolved fixed

In my RCP application we hook a control into IFocusService using IFocusService.addFocusTracker(Control, String) When the underlying control is disposed we unhook it using IFocusService.removeFocusTracker(Control) However during shutdown the focus service is disposed before the control is disposed. This nulls this field FocusControlSourceProvider.controlToId which leads to an NPE when we try to unhook the control. This is more irritating than anything else as the exception is handled somewhere but I'd prefer not to see random NPE's when running in debug. The only robust work around I can see is to use reflection to check whether the controlToId field is null. I think that a null-guard should be all that's required in removeFocusTracker:- if (controlToId == null) { return; }

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/menus/FocusControlSourceProvider.java