Program: 105458
Project: 105458
Buggy source:
@Override @DB public Pair<Boolean,Long> validateAndAddVsm(final String vsmIp,final String vsmUser,final String vsmPassword,final long clusterId,String clusterName) throws ResourceInUseException {
  CiscoNexusVSMDeviceVO vsm=null;
  boolean vsmAdded=false;
  Long vsmId=0L;
  if (vsmIp != null && vsmUser != null && vsmPassword != null) {
    NetconfHelper netconfClient;
    try {
      netconfClient=new NetconfHelper(vsmIp,vsmUser,vsmPassword);
      netconfClient.disconnect();
    }
 catch (    CloudRuntimeException e) {
      String msg="String_Node_Str" + vsmUser + "String_Node_Str"+ vsmIp;
      s_logger.error(msg);
      _clusterDao.remove(clusterId);
      throw new CloudRuntimeException(msg);
    }
    vsm=_vsmDao.getVSMbyIpaddress(vsmIp);
    if (vsm != null) {
      List<ClusterVSMMapVO> clusterList=_clusterVSMDao.listByVSMId(vsm.getId());
      if (clusterList != null && !clusterList.isEmpty()) {
        s_logger.error("String_Node_Str");
        ResourceInUseException ex=new ResourceInUseException("String_Node_Str");
        ClusterVO cluster=_clusterDao.findById(clusterList.get(0).getClusterId());
        ex.addProxyObject(cluster.getUuid());
        _clusterDao.remove(clusterId);
        throw ex;
      }
    }
    vsm=Transaction.execute(new TransactionCallback<CiscoNexusVSMDeviceVO>(){
      @Override public CiscoNexusVSMDeviceVO doInTransaction(      TransactionStatus status){
        CiscoNexusVSMDeviceVO vsm=null;
        if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
          vsm=new CiscoNexusVSMDeviceVO(vsmIp,vsmUser,vsmPassword);
          vsm=_vsmDao.persist(vsm);
        }
        vsm=_vsmDao.getVSMbyIpaddress(vsmIp);
        if (vsm != null) {
          ClusterVSMMapVO connectorObj=new ClusterVSMMapVO(clusterId,vsm.getId());
          _clusterVSMDao.persist(connectorObj);
        }
        return vsm;
      }
    }
);
  }
 else {
    String msg;
    msg="String_Node_Str" + Config.VmwareUseNexusVSwitch.toString() + "String_Node_Str";
    if (vsmIp == null) {
      msg+="String_Node_Str";
    }
    if (vsmUser == null) {
      msg+="String_Node_Str";
    }
    if (vsmPassword == null) {
      if (vsmUser != null) {
        msg+="String_Node_Str" + vsmUser + "String_Node_Str";
      }
 else {
        msg+="String_Node_Str";
      }
    }
    s_logger.error(msg);
    _clusterDao.remove(clusterId);
    throw new CloudRuntimeException(msg);
  }
  if (vsm != null) {
    vsmAdded=true;
    vsmId=vsm.getId();
  }
  return new Pair<Boolean,Long>(vsmAdded,vsmId);
}

Fixed version (ground truth):
@Override @DB public Pair<Boolean,Long> validateAndAddVsm(final String vsmIp,final String vsmUser,final String vsmPassword,final long clusterId,String clusterName) throws ResourceInUseException {
  CiscoNexusVSMDeviceVO vsm=null;
  boolean vsmAdded=false;
  Long vsmId=0L;
  if (vsmIp != null && vsmUser != null && vsmPassword != null) {
    NetconfHelper netconfClient;
    try {
      netconfClient=new NetconfHelper(vsmIp,vsmUser,vsmPassword);
      netconfClient.disconnect();
    }
 catch (    CloudRuntimeException e) {
      String msg="String_Node_Str" + vsmUser + "String_Node_Str"+ vsmIp;
      s_logger.error(msg);
      _clusterDao.remove(clusterId);
      throw new CloudRuntimeException(msg);
    }
    vsm=_vsmDao.getVSMbyIpaddress(vsmIp);
    if (vsm != null) {
      List<ClusterVSMMapVO> clusterList=_clusterVSMDao.listByVSMId(vsm.getId());
      if (clusterList != null && !clusterList.isEmpty()) {
        s_logger.error("String_Node_Str");
        ResourceInUseException ex=new ResourceInUseException("String_Node_Str");
        ClusterVO cluster=_clusterDao.findById(clusterList.get(0).getClusterId());
        ex.addProxyObject(cluster.getUuid());
        _clusterDao.remove(clusterId);
        throw ex;
      }
    }
    vsm=Transaction.execute(new TransactionCallback<CiscoNexusVSMDeviceVO>(){
      @Override public CiscoNexusVSMDeviceVO doInTransaction(      TransactionStatus status){
        CiscoNexusVSMDeviceVO vsm=null;
        if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
          vsm=new CiscoNexusVSMDeviceVO(vsmIp,vsmUser,vsmPassword);
          _vsmDao.persist(vsm);
        }
        vsm=_vsmDao.getVSMbyIpaddress(vsmIp);
        if (vsm != null) {
          ClusterVSMMapVO connectorObj=new ClusterVSMMapVO(clusterId,vsm.getId());
          _clusterVSMDao.persist(connectorObj);
        }
        return vsm;
      }
    }
);
  }
 else {
    String msg;
    msg="String_Node_Str" + Config.VmwareUseNexusVSwitch.toString() + "String_Node_Str";
    if (vsmIp == null) {
      msg+="String_Node_Str";
    }
    if (vsmUser == null) {
      msg+="String_Node_Str";
    }
    if (vsmPassword == null) {
      if (vsmUser != null) {
        msg+="String_Node_Str" + vsmUser + "String_Node_Str";
      }
 else {
        msg+="String_Node_Str";
      }
    }
    s_logger.error(msg);
    _clusterDao.remove(clusterId);
    throw new CloudRuntimeException(msg);
  }
  if (vsm != null) {
    vsmAdded=true;
    vsmId=vsm.getId();
  }
  return new Pair<Boolean,Long>(vsmAdded,vsmId);
}