Program: 106264
Project: 106264
Buggy source:
@Override public ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
  String providerName=cmd.getProviderName();
  DataStoreProvider storeProvider=_dataStoreProviderMgr.getDataStoreProvider(providerName);
  if (storeProvider == null) {
    storeProvider=_dataStoreProviderMgr.getDefaultImageDataStoreProvider();
    if (storeProvider == null) {
      throw new InvalidParameterValueException("String_Node_Str" + providerName);
    }
  }
  Long dcId=cmd.getZoneId();
  String url=cmd.getUrl();
  Map details=cmd.getDetails();
  ScopeType scopeType=ScopeType.ZONE;
  if (dcId == null) {
    scopeType=ScopeType.REGION;
  }
  if (!((ImageStoreProvider)storeProvider).isScopeSupported(scopeType)) {
    throw new InvalidParameterValueException("String_Node_Str" + providerName + "String_Node_Str"+ scopeType);
  }
  List<ImageStoreVO> imageStores=_imageStoreDao.listAll();
  for (  ImageStoreVO store : imageStores) {
    if (!store.getProviderName().equalsIgnoreCase(providerName)) {
      throw new InvalidParameterValueException("String_Node_Str" + store.getProviderName() + "String_Node_Str");
    }
  }
  if (dcId != null) {
    DataCenterVO zone=_dcDao.findById(dcId);
    if (zone == null) {
      throw new InvalidParameterValueException("String_Node_Str" + dcId);
    }
    Account account=UserContext.current().getCaller();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
      PermissionDeniedException ex=new PermissionDeniedException("String_Node_Str");
      ex.addProxyObject(zone,dcId,"String_Node_Str");
      throw ex;
    }
  }
  Map<String,Object> params=new HashMap<String,Object>();
  params.put("String_Node_Str",dcId);
  params.put("String_Node_Str",cmd.getUrl());
  params.put("String_Node_Str",cmd.getUrl());
  params.put("String_Node_Str",details);
  params.put("String_Node_Str",scopeType);
  params.put("String_Node_Str",storeProvider.getName());
  params.put("String_Node_Str",DataStoreRole.Image);
  DataStoreLifeCycle lifeCycle=storeProvider.getDataStoreLifeCycle();
  DataStore store=null;
  try {
    store=lifeCycle.initialize(params);
  }
 catch (  Exception e) {
    s_logger.debug("String_Node_Str",e);
    throw new CloudRuntimeException("String_Node_Str",e);
  }
  if (((ImageStoreProvider)storeProvider).needDownloadSysTemplate()) {
    this._imageSrv.downloadBootstrapSysTemplate(store);
  }
 else {
    this._imageSrv.addSystemVMTemplatesToSecondary(store);
  }
  this.associateCrosszoneTemplatesToZone(dcId);
  return (ImageStore)_dataStoreMgr.getDataStore(store.getId(),DataStoreRole.Image);
}

Fixed version (ground truth):
@Override public ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
  String providerName=cmd.getProviderName();
  DataStoreProvider storeProvider=_dataStoreProviderMgr.getDataStoreProvider(providerName);
  if (storeProvider == null) {
    storeProvider=_dataStoreProviderMgr.getDefaultImageDataStoreProvider();
    if (storeProvider == null) {
      throw new InvalidParameterValueException("String_Node_Str" + providerName);
    }
  }
  Long dcId=cmd.getZoneId();
  String url=cmd.getUrl();
  Map details=cmd.getDetails();
  ScopeType scopeType=ScopeType.ZONE;
  if (dcId == null) {
    scopeType=ScopeType.REGION;
  }
  if (!((ImageStoreProvider)storeProvider).isScopeSupported(scopeType)) {
    throw new InvalidParameterValueException("String_Node_Str" + providerName + "String_Node_Str"+ scopeType);
  }
  List<ImageStoreVO> imageStores=_imageStoreDao.listImageStores();
  for (  ImageStoreVO store : imageStores) {
    if (!store.getProviderName().equalsIgnoreCase(providerName)) {
      throw new InvalidParameterValueException("String_Node_Str" + store.getProviderName() + "String_Node_Str");
    }
  }
  if (dcId != null) {
    DataCenterVO zone=_dcDao.findById(dcId);
    if (zone == null) {
      throw new InvalidParameterValueException("String_Node_Str" + dcId);
    }
    Account account=UserContext.current().getCaller();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
      PermissionDeniedException ex=new PermissionDeniedException("String_Node_Str");
      ex.addProxyObject(zone,dcId,"String_Node_Str");
      throw ex;
    }
  }
  Map<String,Object> params=new HashMap<String,Object>();
  params.put("String_Node_Str",dcId);
  params.put("String_Node_Str",cmd.getUrl());
  params.put("String_Node_Str",cmd.getUrl());
  params.put("String_Node_Str",details);
  params.put("String_Node_Str",scopeType);
  params.put("String_Node_Str",storeProvider.getName());
  params.put("String_Node_Str",DataStoreRole.Image);
  DataStoreLifeCycle lifeCycle=storeProvider.getDataStoreLifeCycle();
  DataStore store=null;
  try {
    store=lifeCycle.initialize(params);
  }
 catch (  Exception e) {
    s_logger.debug("String_Node_Str",e);
    throw new CloudRuntimeException("String_Node_Str",e);
  }
  if (((ImageStoreProvider)storeProvider).needDownloadSysTemplate()) {
    this._imageSrv.downloadBootstrapSysTemplate(store);
  }
 else {
    this._imageSrv.addSystemVMTemplatesToSecondary(store);
  }
  this.associateCrosszoneTemplatesToZone(dcId);
  return (ImageStore)_dataStoreMgr.getDataStore(store.getId(),DataStoreRole.Image);
}