Program: 106075
Project: 106075
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);
    }
    providerName=storeProvider.getName();
  }
  Long dcId=cmd.getZoneId();
  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=CallContext.current().getCallingAccount();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
      PermissionDeniedException ex=new PermissionDeniedException("String_Node_Str");
      ex.addProxyObject(zone.getUuid(),"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.getName());
  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;
  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()) {
    _imageSrv.downloadBootstrapSysTemplate(store);
  }
 else {
    _imageSrv.addSystemVMTemplatesToSecondary(store);
  }
  associateCrosszoneTemplatesToZone(dcId);
  if (scopeType == ScopeType.REGION) {
    duplicateCacheStoreRecordsToRegionStore(store.getId());
  }
  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);
    }
    providerName=storeProvider.getName();
  }
  Long dcId=cmd.getZoneId();
  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=CallContext.current().getCallingAccount();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
      PermissionDeniedException ex=new PermissionDeniedException("String_Node_Str");
      ex.addProxyObject(zone.getUuid(),"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.getName());
  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;
  try {
    store=lifeCycle.initialize(params);
  }
 catch (  Exception e) {
    s_logger.debug("String_Node_Str" + e.getMessage(),e);
    throw new CloudRuntimeException("String_Node_Str" + e.getMessage(),e);
  }
  if (((ImageStoreProvider)storeProvider).needDownloadSysTemplate()) {
    _imageSrv.downloadBootstrapSysTemplate(store);
  }
 else {
    _imageSrv.addSystemVMTemplatesToSecondary(store);
  }
  associateCrosszoneTemplatesToZone(dcId);
  if (scopeType == ScopeType.REGION) {
    duplicateCacheStoreRecordsToRegionStore(store.getId());
  }
  return (ImageStore)_dataStoreMgr.getDataStore(store.getId(),DataStoreRole.Image);
}