From 102fc7b8d586063db726774e693df38a49cb7b40 Mon Sep 17 00:00:00 2001 From: Stéphane Bégaudeau Date: Fri, 27 Jan 2017 09:55:05 +0100 Subject: [510279] Fix potential NPE in AbstractEEFWidgetLifecycleManager AbstractEEFWidgetLifecycleManager.lockedBy* are called asynchronously and sometimes this can occur at a time when the ControlDecoration has been disposed, causing NPEs in ControlDecoration.setImage() when it accesses control.getShell(). ControlDecoration does not have an isDisposed() method, but testing for getControl() != null is equivalent. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=510279 Change-Id: Icf155151eacbdbf50db4161955222f566dadf70e Signed-off-by: Stéphane Bégaudeau --- .../widgets/AbstractEEFWidgetLifecycleManager.java | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/widgets/AbstractEEFWidgetLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/widgets/AbstractEEFWidgetLifecycleManager.java index e56f7938c..01b1c3eb2 100644 --- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/widgets/AbstractEEFWidgetLifecycleManager.java +++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/api/widgets/AbstractEEFWidgetLifecycleManager.java @@ -343,7 +343,7 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec /** * Handles the change in the lock status by switching the user interface to a "locked by me", "locked by other" or * "unlocked" state. - * + * * @param status * The lock status */ @@ -381,10 +381,12 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec * validation control. */ protected void lockedByMe() { - this.controlDecoration.hide(); - this.controlDecoration.setDescriptionText(Messages.AbstractEEFWidgetLifecycleManager_lockedByMe); - this.controlDecoration.setImage(EEFIdeUiPlugin.getPlugin().getImageRegistry().get(Icons.PERMISSION_GRANTED_TO_CURRENT_USER_EXCLUSIVELY)); - this.controlDecoration.show(); + if (this.controlDecoration.getControl() != null) { + this.controlDecoration.hide(); + this.controlDecoration.setDescriptionText(Messages.AbstractEEFWidgetLifecycleManager_lockedByMe); + this.controlDecoration.setImage(EEFIdeUiPlugin.getPlugin().getImageRegistry().get(Icons.PERMISSION_GRANTED_TO_CURRENT_USER_EXCLUSIVELY)); + this.controlDecoration.show(); + } } /** @@ -395,20 +397,24 @@ public abstract class AbstractEEFWidgetLifecycleManager extends AbstractEEFLifec protected void lockedByOther() { this.setEnabled(false); - this.controlDecoration.hide(); - this.controlDecoration.setDescriptionText(Messages.AbstractEEFWidgetLifecycleManager_lockedByOther); - this.controlDecoration.setImage(EEFIdeUiPlugin.getPlugin().getImageRegistry().get(Icons.PERMISSION_DENIED)); - this.controlDecoration.show(); + if (this.controlDecoration.getControl() != null) { + this.controlDecoration.hide(); + this.controlDecoration.setDescriptionText(Messages.AbstractEEFWidgetLifecycleManager_lockedByOther); + this.controlDecoration.setImage(EEFIdeUiPlugin.getPlugin().getImageRegistry().get(Icons.PERMISSION_DENIED)); + this.controlDecoration.show(); + } } /** - * Sets the appearance and behavior of the widget in order to indicate that the semantic element used by the widget is - * currently unlocked. As a result, it will set back the widget to its default state. + * Sets the appearance and behavior of the widget in order to indicate that the semantic element used by the widget + * is currently unlocked. As a result, it will set back the widget to its default state. */ protected void unlocked() { this.setEnabled(this.isEnabled()); - this.controlDecoration.hide(); + if (this.controlDecoration.getControl() != null) { + this.controlDecoration.hide(); + } } /** -- cgit v1.2.3