Vojtech Szocs has uploaded a new change for review.

Change subject: webadmin: Guard against premature CommonModel nullification
......................................................................

webadmin: Guard against premature CommonModel nullification

This patch ensures that CommonModel instance gets nullified via
deferred command, only after all UiCommon-related processing is
over.

In case some SyncSearch response callback still executes after
that, "getModel() != null" condition in DataBoundTabModelProvider
should guard against NullPointerExceptions.

This patch also removes "CommonModel != null" assertions from
UiCommonModelResolver, since it's possible for CommonModel
reference to be null in some edge-case scenarios.

Change-Id: I2bf55e75d97006d230bf503fac026722321435d0
Bug-Url: https://bugzilla.redhat.com/924670
Signed-off-by: Vojtech Szocs <[email protected]>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/UiCommonModelResolver.java
3 files changed, 13 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/26/13326/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
index fe28d30..47a9b48 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
@@ -8,6 +8,8 @@
 import org.ovirt.engine.ui.uicompat.EventArgs;
 import org.ovirt.engine.ui.uicompat.IEventListener;
 
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 import com.google.gwt.event.shared.EventBus;
 
 /**
@@ -36,12 +38,19 @@
         commonModel.getSignedOutEvent().addListener(new IEventListener() {
             @Override
             public void eventRaised(Event ev, Object sender, EventArgs args) {
-                // Clear CommonModel reference after the user signs out
-                commonModel = null;
-
                 loginModel.resetAfterLogout();
                 user.onUserLogout();
                 frontendFailureEventListener.hide();
+
+                // Clear CommonModel reference after the user signs out,
+                // use deferred command to ensure the reference is cleared
+                // only after all UiCommon-related processing is over
+                Scheduler.get().scheduleDeferred(new ScheduledCommand() {
+                    @Override
+                    public void execute() {
+                        commonModel = null;
+                    }
+                });
             }
         });
     }
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
index b16a421..6fe420c 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
@@ -49,7 +49,7 @@
         getModel().getItemsChangedEvent().addListener(new IEventListener() {
             @Override
             public void eventRaised(Event ev, Object sender, EventArgs args) {
-                if (handleItemsChangedEvent()) {
+                if (getModel() != null && handleItemsChangedEvent()) {
                     updateData();
                 }
             }
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/UiCommonModelResolver.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/UiCommonModelResolver.java
index ee40042..cec34a1 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/UiCommonModelResolver.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/UiCommonModelResolver.java
@@ -19,8 +19,6 @@
     @SuppressWarnings("unchecked")
     public static <M extends SearchableListModel> M getMainListModel(
             CommonModel commonModel, Class<M> mainModelClass) {
-        assert (commonModel != null) : "CommonModel must not be null"; 
//$NON-NLS-1$
-
         for (SearchableListModel list : commonModel.getItems()) {
             if (list != null && list.getClass().equals(mainModelClass)) {
                 return (M) list;
@@ -41,8 +39,6 @@
     @SuppressWarnings("unchecked")
     public static <M extends ListWithDetailsModel, D extends EntityModel> D 
getDetailListModel(
             CommonModel commonModel, Class<M> mainModelClass, Class<D> 
detailModelClass) {
-        assert (commonModel != null) : "CommonModel must not be null"; 
//$NON-NLS-1$
-
         M mainListModel = getMainListModel(commonModel, mainModelClass);
 
         for (EntityModel details : mainListModel.getDetailModels()) {


--
To view, visit http://gerrit.ovirt.org/13326
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2bf55e75d97006d230bf503fac026722321435d0
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Vojtech Szocs <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to