Project: Eclipse_Platform_UI
Bug 276371 [ErrorHandling] Need to clean up dialog field after failure in status handling
Reported: 2009-05-14 15:46:50 | Status: verified fixed

3.5 RC1 I was experimenting in WorkbenchStatusDialogManager, trying to move the dialog.open() down past the support tray open. It didn't work, but the important part for this bug is that the dialog field was now non-null but also not fully initialized (no shell). Any call to status handling after that results in an error because of if (dialog == null || dialog.getShell().isDisposed()) { as in: java.lang.NullPointerException at org.eclipse.ui.statushandlers.WorkbenchStatusDialogManager.addStatusAdapter(WorkbenchStatusDialogManager.java:1247) at org.eclipse.ui.statushandlers.WorkbenchErrorHandler.showStatusAdapter(WorkbenchErrorHandler.java:99) I'm not sure how representative this error is but it's maybe prudent to clean up any cached objects (like WorkbenchStatusDialogManager instance) if we get an exception handling statuses. I can see two approaches: 1) In WorkbenchStatusDialogManager, use a temp field for dialog and only assign it to the instance field WorkbenchStatusDialogManager.dialog after we do the open. If we bomb on the open, then the field remains null. To be extra prudent, at the start if the field was non-null we'd assign it to the temp then null the field, thus ensuring it can only have a value after a successful open. 2) In WorkbenchErrorHandler.showStatusAdapter(), catch exceptions around getStatusDialogManager().addStatusAdapter(statusAdapter, block); and null out the statusDialogManager on exception, then rethrow up the chain. The second approach would catch a wider set of potential problems, both because more errors will be caught (not just the open), and also because WorkbenchStatusDialogManager has a number of fields which might be partially initialized and thus the source of errors.

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/statushandlers/WorkbenchStatusDialogManager.java tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/statushandlers/StatusDialogManagerTest.java