Program: 137691
Project: 137691
Buggy source:
private void setConnectionState(final AbstractAnalysisMetadataPage masterPage,final DataManager dataManager){
  DataManager newDataManager=dataManager;
  final DataManager fianlDataManager;
  if (newDataManager != null) {
    Property prop=PropertyHelper.getProperty(newDataManager);
    masterPage.reloadDataproviderAndFillConnCombo();
    try {
      if (newDataManager.eIsProxy()) {
        IRepositoryViewObject lastVersion=ProxyRepositoryFactory.getInstance().getLastVersion(prop.getId());
        prop=lastVersion.getProperty();
        newDataManager=(DataManager)PropertyHelper.getModelElement(prop);
      }
    }
 catch (    PersistenceException e1) {
      log.error(e1,e1);
    }
    fianlDataManager=newDataManager;
    Object value=null;
    if (SwitchHelpers.CONNECTION_SWITCH.doSwitch(newDataManager) != null) {
      value=masterPage.getConnCombo().getData(prop.getDisplayName() + RepositoryNodeHelper.getConnectionType(newDataManager));
    }
    Integer index=0;
    if (value != null && value instanceof Integer) {
      index=(Integer)value;
    }
    masterPage.getConnCombo().select(index);
    if (prop != null && prop.getItem() != null && prop.getItem().getState() != null && prop.getItem().getState().isDeleted()) {
      masterPage.getLabelConnDeleted().setVisible(true);
      masterPage.getLabelConnDeleted().setText(DefaultMessagesImpl.getString("String_Node_Str",prop.getDisplayName()));
    }
 else {
      masterPage.getLabelConnDeleted().setVisible(false);
    }
    if (selectionListener == null) {
      selectionListener=new SelectionListener(){
        private int prevSelect=masterPage.getConnCombo().getSelectionIndex();
        private Connection dataProvider=(Connection)fianlDataManager;
        public void widgetDefaultSelected(        SelectionEvent e){
        }
        public void widgetSelected(        SelectionEvent e){
          ReturnCode rc=selectedObjectAvailable();
          if (rc.isOk()) {
            dataProvider=callChangeConnectionAction(masterPage,prevSelect,dataProvider);
            prevSelect=masterPage.getConnCombo().getSelectionIndex();
          }
 else {
            MessageDialogWithToggle.openError(null,DefaultMessagesImpl.getString("String_Node_Str"),DefaultMessagesImpl.getString("String_Node_Str",rc.getMessage()));
            masterPage.reloadDataproviderAndFillConnCombo();
            masterPage.getConnCombo().removeSelectionListener(selectionListener);
            String uuid=ResourceHelper.getUUID(dataProvider);
            if (uuid != null) {
              int itemCount=masterPage.getConnCombo().getItemCount();
              for (int i=0; i < itemCount; i++) {
                Object connectionObj=masterPage.getConnCombo().getData(String.valueOf(i));
                RepositoryNode repoNode=(RepositoryNode)connectionObj;
                Connection connection=getConnectionFromRepositoryNode(repoNode);
                if (connection != null && uuid.endsWith(ResourceHelper.getUUID(connection))) {
                  masterPage.getConnCombo().select(i);
                  break;
                }
              }
            }
            masterPage.getConnCombo().addSelectionListener(selectionListener);
          }
        }
        /** 
 * check the connection is available or not(the connection is exist and not proxy, don't check the connection).
 * @return a ReturnCode, the message is the connection label
 */
        private ReturnCode selectedObjectAvailable(){
          ReturnCode rc=new ReturnCode("String_Node_Str",Boolean.FALSE);
          Object connectionObj=masterPage.getConnCombo().getData(masterPage.getConnCombo().getSelectionIndex() + PluginConstant.EMPTY_STRING);
          RepositoryNode repoNode=(RepositoryNode)connectionObj;
          rc.setMessage(repoNode.getLabel());
          Connection connection=getConnectionFromRepositoryNode(repoNode);
          if (connection != null && !connection.eIsProxy()) {
            rc.setOk(true);
          }
          return rc;
        }
        /** 
 * DOC xqliu Comment method "getConnectionFromRepositoryNode".
 * @param repoNode
 * @return
 */
        private Connection getConnectionFromRepositoryNode(        RepositoryNode repoNode){
          Connection connection=null;
          IRepositoryViewObject repoViewObject=repoNode.getObject();
          if (repoViewObject != null) {
            Property property=repoViewObject.getProperty();
            if (property != null) {
              Item item=property.getItem();
              if (item != null && item instanceof ConnectionItem) {
                connection=((ConnectionItem)item).getConnection();
              }
            }
          }
          return connection;
        }
      }
;
      masterPage.getConnCombo().addSelectionListener(selectionListener);
    }
  }
 else {
    masterPage.getConnCombo().setText("String_Node_Str");
  }
}

Fixed version (ground truth):
private void setConnectionState(final AbstractAnalysisMetadataPage masterPage,final DataManager dataManager){
  DataManager newDataManager=dataManager;
  final DataManager fianlDataManager;
  if (newDataManager != null) {
    Property prop=PropertyHelper.getProperty(newDataManager);
    masterPage.reloadDataproviderAndFillConnCombo();
    if (newDataManager.eIsProxy()) {
      newDataManager=(DataManager)EObjectHelper.resolveObject(newDataManager);
    }
    fianlDataManager=newDataManager;
    Object value=null;
    if (SwitchHelpers.CONNECTION_SWITCH.doSwitch(newDataManager) != null) {
      value=masterPage.getConnCombo().getData(prop.getDisplayName() + RepositoryNodeHelper.getConnectionType(newDataManager));
    }
    Integer index=0;
    if (value != null && value instanceof Integer) {
      index=(Integer)value;
    }
    masterPage.getConnCombo().select(index);
    if (prop != null && prop.getItem() != null && prop.getItem().getState() != null && prop.getItem().getState().isDeleted()) {
      masterPage.getLabelConnDeleted().setVisible(true);
      masterPage.getLabelConnDeleted().setText(DefaultMessagesImpl.getString("String_Node_Str",prop.getDisplayName()));
    }
 else {
      masterPage.getLabelConnDeleted().setVisible(false);
    }
    if (selectionListener == null) {
      selectionListener=new SelectionListener(){
        private int prevSelect=masterPage.getConnCombo().getSelectionIndex();
        private Connection dataProvider=(Connection)fianlDataManager;
        public void widgetDefaultSelected(        SelectionEvent e){
        }
        public void widgetSelected(        SelectionEvent e){
          ReturnCode rc=selectedObjectAvailable();
          if (rc.isOk()) {
            if (dataProvider.eIsProxy()) {
              dataProvider=(Connection)EObjectHelper.resolveObject(dataProvider);
            }
            dataProvider=callChangeConnectionAction(masterPage,prevSelect,dataProvider);
            prevSelect=masterPage.getConnCombo().getSelectionIndex();
          }
 else {
            MessageDialogWithToggle.openError(null,DefaultMessagesImpl.getString("String_Node_Str"),DefaultMessagesImpl.getString("String_Node_Str",rc.getMessage()));
            masterPage.reloadDataproviderAndFillConnCombo();
            masterPage.getConnCombo().removeSelectionListener(selectionListener);
            String uuid=ResourceHelper.getUUID(dataProvider);
            if (uuid != null) {
              int itemCount=masterPage.getConnCombo().getItemCount();
              for (int i=0; i < itemCount; i++) {
                Object connectionObj=masterPage.getConnCombo().getData(String.valueOf(i));
                RepositoryNode repoNode=(RepositoryNode)connectionObj;
                Connection connection=getConnectionFromRepositoryNode(repoNode);
                if (connection != null && uuid.endsWith(ResourceHelper.getUUID(connection))) {
                  masterPage.getConnCombo().select(i);
                  break;
                }
              }
            }
            masterPage.getConnCombo().addSelectionListener(selectionListener);
          }
        }
        /** 
 * check the connection is available or not(the connection is exist and not proxy, don't check the connection).
 * @return a ReturnCode, the message is the connection label
 */
        private ReturnCode selectedObjectAvailable(){
          ReturnCode rc=new ReturnCode("String_Node_Str",Boolean.FALSE);
          Object connectionObj=masterPage.getConnCombo().getData(masterPage.getConnCombo().getSelectionIndex() + PluginConstant.EMPTY_STRING);
          RepositoryNode repoNode=(RepositoryNode)connectionObj;
          rc.setMessage(repoNode.getLabel());
          Connection connection=getConnectionFromRepositoryNode(repoNode);
          if (connection != null && !connection.eIsProxy()) {
            rc.setOk(true);
          }
          return rc;
        }
        /** 
 * DOC xqliu Comment method "getConnectionFromRepositoryNode".
 * @param repoNode
 * @return
 */
        private Connection getConnectionFromRepositoryNode(        RepositoryNode repoNode){
          Connection connection=null;
          IRepositoryViewObject repoViewObject=repoNode.getObject();
          if (repoViewObject != null) {
            Property property=repoViewObject.getProperty();
            if (property != null) {
              Item item=property.getItem();
              if (item != null && item instanceof ConnectionItem) {
                connection=((ConnectionItem)item).getConnection();
              }
            }
          }
          return connection;
        }
      }
;
      masterPage.getConnCombo().addSelectionListener(selectionListener);
    }
  }
 else {
    masterPage.getConnCombo().setText("String_Node_Str");
  }
}