Source:
<code>public void newEntity() { if (getWindow() != null) { return; } ClusterModel clusterModel = new ClusterModel(); clusterModel.init(false); setWindow(clusterModel); clusterModel.setTitle(ConstantsManager.getInstance().getConstants().newClusterTitle()); clusterModel.setHelpTag(HelpTag.new_cluster); clusterModel.setHashName("new_cluster"); clusterModel.setIsNew(true); AsyncQuery _asyncQuery = new AsyncQuery(); _asyncQuery.setModel(this); _asyncQuery.asyncCallback = new INewAsyncCallback() { @Override public void onSuccess(Object model, Object result) { ClusterListModel clModel = (ClusterListModel) model; ClusterModel cModel = (ClusterModel) clModel.getWindow(); ArrayList<StoragePool> dataCenters = (ArrayList<StoragePool>) result; cModel.getDataCenter().setItems(dataCenters); if (clModel.getSystemTreeSelectedItem() != null && clModel.getSystemTreeSelectedItem().getType() != SystemTreeItemType.System) { StoragePool selectDataCenter = (StoragePool) clModel.getSystemTreeSelectedItem().getEntity(); cModel.getDataCenter().setSelectedItem(Linq.firstOrDefault(dataCenters, <START> new Linq.DataCenterPredicate(selectDataCenter.getId()))); <END> cModel.getDataCenter().setIsChangable(false); } else { cModel.getDataCenter().setSelectedItem(Linq.firstOrDefault(dataCenters)); } } }; AsyncDataProvider.getDataCenterList(_asyncQuery); UICommand tempVar = new UICommand("OnSave", this); tempVar.setTitle(ConstantsManager.getInstance().getConstants().ok()); tempVar.setIsDefault(true); clusterModel.getCommands().add(tempVar); UICommand tempVar2 = new UICommand("Cancel", this); tempVar2.setTitle(ConstantsManager.getInstance().getConstants().cancel()); tempVar2.setIsCancel(true); clusterModel.getCommands().add(tempVar2); }</code><technical_language>a NPE exception is thrown here</technical_language>

Target:
public void newEntity() { if (getWindow() != null) { return; } ClusterModel clusterModel = new ClusterModel(); clusterModel.init(false); setWindow(clusterModel); clusterModel.setTitle(ConstantsManager.getInstance().getConstants().newClusterTitle()); clusterModel.setHelpTag(HelpTag.new_cluster); clusterModel.setHashName("new_cluster"); clusterModel.setIsNew(true); AsyncQuery _asyncQuery = new AsyncQuery(); _asyncQuery.setModel(this); _asyncQuery.asyncCallback = new INewAsyncCallback() { @Override public void onSuccess(Object model, Object result) { ClusterListModel clModel = (ClusterListModel) model; ClusterModel cModel = (ClusterModel) clModel.getWindow(); ArrayList<StoragePool> dataCenters = (ArrayList<StoragePool>) result; cModel.getDataCenter().setItems(dataCenters); if (clModel.getSystemTreeSelectedItem() != null && clModel.getSystemTreeSelectedItem().getType() != SystemTreeItemType.System) { SystemTreeItemModel treeSelectedItem = clModel.getSystemTreeSelectedItem(); SystemTreeItemModel treeSelectedDc = SystemTreeItemModel.findAncestor(SystemTreeItemType.DataCenter, treeSelectedItem); StoragePool selectDataCenter = (StoragePool) treeSelectedDc.getEntity(); cModel.getDataCenter().setSelectedItem(Linq.firstOrDefault(dataCenters, new Linq.DataCenterPredicate(selectDataCenter.getId()))); cModel.getDataCenter().setIsChangable(false); } else { cModel.getDataCenter().setSelectedItem(Linq.firstOrDefault(dataCenters)); } UICommand tempVar = new UICommand("OnSave", clModel); tempVar.setTitle(ConstantsManager.getInstance().getConstants().ok()); tempVar.setIsDefault(true); cModel.getCommands().add(tempVar); UICommand tempVar2 = new UICommand("Cancel", clModel); tempVar2.setTitle(ConstantsManager.getInstance().getConstants().cancel()); tempVar2.setIsCancel(true); cModel.getCommands().add(tempVar2); } }; AsyncDataProvider.getDataCenterList(_asyncQuery); }