Martin Betak has uploaded a new change for review.

Change subject: webadmin: Fix NPE in SnapshotModel
......................................................................

webadmin: Fix NPE in SnapshotModel

CancelCommand was not properly initialized in SnapshotModel.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1056651
Change-Id: I21de53a8f9092085beee28124ef2321538e76669
Signed-off-by: Martin Betak <[email protected]>
---
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SnapshotModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmSnapshotListModel.java
3 files changed, 20 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/99/23599/1

diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SnapshotModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SnapshotModel.java
index 32c2917..eb8311d 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SnapshotModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SnapshotModel.java
@@ -21,6 +21,7 @@
 import org.ovirt.engine.ui.frontend.AsyncQuery;
 import org.ovirt.engine.ui.frontend.Frontend;
 import org.ovirt.engine.ui.frontend.INewAsyncCallback;
+import org.ovirt.engine.ui.uicommonweb.ICommandTarget;
 import org.ovirt.engine.ui.uicommonweb.Linq;
 import org.ovirt.engine.ui.uicommonweb.UICommand;
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
@@ -168,6 +169,22 @@
         setSnapshotDisks(new ListModel());
     }
 
+    public static SnapshotModel createNewSnapshotModel(VM vm, ICommandTarget 
cancelCommandTarget) {
+        SnapshotModel model = new SnapshotModel();
+        
model.setTitle(ConstantsManager.getInstance().getConstants().createSnapshotTitle());
+        model.setHashName("create_snapshot"); //$NON-NLS-1$
+        model.setVm(vm);
+
+        // the cancel command has to be created be before the call to 
initialize to avoid race condition
+        model.setCancelCommand(new UICommand("Cancel", cancelCommandTarget) 
//$NON-NLS-1$
+                                       
.setTitle(ConstantsManager.getInstance().getConstants().cancel())
+                                       .setIsCancel(true));
+
+        model.initialize();
+
+        return model;
+    }
+
     @Override
     public Snapshot getEntity() {
         return (Snapshot) super.getEntity();
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
index a50a65c..830f0e7 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java
@@ -885,18 +885,9 @@
             return;
         }
 
-        SnapshotModel model = new SnapshotModel();
-        setWindow(model);
-        
model.setTitle(ConstantsManager.getInstance().getConstants().createSnapshotTitle());
-        model.setHashName("create_snapshot"); //$NON-NLS-1$
-
-        model.setVm(vm);
+        SnapshotModel model = SnapshotModel.createNewSnapshotModel(vm, this);
         model.setValidateByVmSnapshots(true);
-        model.initialize();
-
-        model.getCommands().add(new UICommand("Cancel", this) //$NON-NLS-1$
-                
.setTitle(ConstantsManager.getInstance().getConstants().cancel())
-                .setIsCancel(true));
+        setWindow(model);
     }
 
     @Override
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmSnapshotListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmSnapshotListModel.java
index fad7055..808796c 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmSnapshotListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmSnapshotListModel.java
@@ -497,17 +497,8 @@
             return;
         }
 
-        SnapshotModel model = new SnapshotModel();
+        SnapshotModel model = SnapshotModel.createNewSnapshotModel(vm, this);
         setWindow(model);
-        
model.setTitle(ConstantsManager.getInstance().getConstants().createSnapshotTitle());
-        model.setHashName("create_snapshot"); //$NON-NLS-1$
-
-        model.setVm(vm);
-        model.initialize();
-
-        model.setCancelCommand(new UICommand("Cancel", this) //$NON-NLS-1$
-                
.setTitle(ConstantsManager.getInstance().getConstants().cancel())
-                .setIsCancel(true));
     }
 
     public void postOnNew(List<VdcReturnValueBase> returnValues) {


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

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

Reply via email to