Program: 114764
Project: 114764
Buggy source:
/** 
 * This method imports an API
 * @param pathToArchive            location of the extracted folder of the API
 * @param currentUser              the current logged in user
 * @param isDefaultProviderAllowed decision to keep or replace the provider
 * @throws APIImportException     if there is an error in importing an API
 */
public static void importAPI(String pathToArchive,String currentUser,boolean isDefaultProviderAllowed) throws APIImportException {
  API importedApi=null;
  String prevProvider;
  APIDefinition definitionFromSwagger20=new APIDefinitionFromSwagger20();
  String pathToJSONFile=pathToArchive + APIImportExportConstants.JSON_FILE_LOCATION;
  try {
    String jsonContent=FileUtils.readFileToString(new File(pathToJSONFile));
    JsonElement configElement=new JsonParser().parse(jsonContent);
    JsonObject configObject=configElement.getAsJsonObject();
    JsonObject apiId=configObject.getAsJsonObject(APIImportExportConstants.ID_ELEMENT);
    prevProvider=apiId.get(APIImportExportConstants.PROVIDER_ELEMENT).getAsString();
    String prevTenantDomain=MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(prevProvider));
    String currentTenantDomain=MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(currentUser));
    if (isDefaultProviderAllowed) {
      if (!StringUtils.equals(prevTenantDomain,currentTenantDomain)) {
        String errorMessage="String_Node_Str" + "String_Node_Str";
        log.error(errorMessage);
        throw new APIImportException(errorMessage);
      }
      importedApi=new Gson().fromJson(configElement,API.class);
    }
 else {
      apiId.addProperty(APIImportExportConstants.PROVIDER_ELEMENT,APIUtil.replaceEmailDomain(currentUser));
      importedApi=new Gson().fromJson(configElement,API.class);
      importedApi=SetCurrentProvidertoAPIProperties(importedApi,currentTenantDomain,prevTenantDomain);
    }
    if (provider.isAPIAvailable(importedApi.getId())) {
      String errorMessage="String_Node_Str" + importedApi.getId().getApiName() + "String_Node_Str"+ importedApi.getId().getVersion();
      log.error(errorMessage);
      throw new APIImportException(errorMessage);
    }
  }
 catch (  IOException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
catch (  APIManagementException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
  Set<Tier> allowedTiers;
  Set<Tier> unsupportedTiersList;
  try {
    allowedTiers=provider.getTiers();
  }
 catch (  APIManagementException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
  if (!(allowedTiers.isEmpty())) {
    unsupportedTiersList=Sets.difference(importedApi.getAvailableTiers(),allowedTiers);
    if (!(unsupportedTiersList.isEmpty())) {
      for (      Tier unsupportedTier : unsupportedTiersList) {
        log.warn("String_Node_Str" + unsupportedTier.getName() + "String_Node_Str");
      }
      importedApi.removeAvailableTiers(unsupportedTiersList);
    }
  }
  try {
    String swaggerContent=FileUtils.readFileToString(new File(pathToArchive + APIImportExportConstants.SWAGGER_DEFINITION_LOCATION));
    provider.addAPI(importedApi);
    addSwaggerDefinition(importedApi.getId(),swaggerContent);
    Set<URITemplate> uriTemplates=definitionFromSwagger20.getURITemplates(importedApi,swaggerContent);
    importedApi.setUriTemplates(uriTemplates);
    Set<Scope> scopes=definitionFromSwagger20.getScopes(swaggerContent);
    importedApi.setScopes(scopes);
    for (    URITemplate uriTemplate : uriTemplates) {
      Scope scope=uriTemplate.getScope();
      if (scope != null && !(APIUtil.isWhiteListedScope(scope.getKey()))) {
        if (provider.isScopeKeyAssigned(importedApi.getId(),scope.getKey(),PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true))) {
          String errorMessage="String_Node_Str" + scope.getKey() + "String_Node_Str"+ "String_Node_Str";
          log.error(errorMessage);
          throw new APIImportException(errorMessage);
        }
      }
    }
    provider.updateAPI(importedApi);
  }
 catch (  APIManagementException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
catch (  IOException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
catch (  FaultGatewaysException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
  addAPIImage(pathToArchive,importedApi);
  addAPIDocuments(pathToArchive,importedApi);
  addAPISequences(pathToArchive,importedApi);
  addAPISpecificSequences(pathToArchive,importedApi);
  addAPIWsdl(pathToArchive,importedApi);
}

Fixed version (ground truth):
/** 
 * This method imports an API
 * @param pathToArchive            location of the extracted folder of the API
 * @param currentUser              the current logged in user
 * @param isDefaultProviderAllowed decision to keep or replace the provider
 * @throws APIImportException     if there is an error in importing an API
 */
public static void importAPI(String pathToArchive,String currentUser,boolean isDefaultProviderAllowed) throws APIImportException {
  API importedApi=null;
  String prevProvider;
  APIDefinition definitionFromSwagger20=new APIDefinitionFromSwagger20();
  String pathToJSONFile=pathToArchive + APIImportExportConstants.JSON_FILE_LOCATION;
  try {
    String jsonContent=FileUtils.readFileToString(new File(pathToJSONFile));
    JsonElement configElement=new JsonParser().parse(jsonContent);
    JsonObject configObject=configElement.getAsJsonObject();
    JsonObject apiId=configObject.getAsJsonObject(APIImportExportConstants.ID_ELEMENT);
    prevProvider=apiId.get(APIImportExportConstants.PROVIDER_ELEMENT).getAsString();
    String prevTenantDomain=MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(prevProvider));
    String currentTenantDomain=MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(currentUser));
    if (isDefaultProviderAllowed) {
      if (!StringUtils.equals(prevTenantDomain,currentTenantDomain)) {
        String errorMessage="String_Node_Str" + "String_Node_Str";
        log.error(errorMessage);
        throw new APIImportException(errorMessage);
      }
      importedApi=new Gson().fromJson(configElement,API.class);
    }
 else {
      apiId.addProperty(APIImportExportConstants.PROVIDER_ELEMENT,APIUtil.replaceEmailDomain(currentUser));
      importedApi=new Gson().fromJson(configElement,API.class);
      importedApi=SetCurrentProvidertoAPIProperties(importedApi,currentTenantDomain,prevTenantDomain);
    }
    if (provider.isAPIAvailable(importedApi.getId())) {
      String errorMessage="String_Node_Str" + importedApi.getId().getApiName() + "String_Node_Str"+ importedApi.getId().getVersion();
      log.error(errorMessage);
      throw new APIImportException(errorMessage);
    }
  }
 catch (  IOException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
catch (  APIManagementException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
  Set<Tier> allowedTiers;
  Set<Tier> unsupportedTiersList;
  try {
    allowedTiers=provider.getTiers();
  }
 catch (  APIManagementException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
  if (!(allowedTiers.isEmpty())) {
    unsupportedTiersList=Sets.difference(importedApi.getAvailableTiers(),allowedTiers);
    if (!(unsupportedTiersList.isEmpty())) {
      for (      Tier unsupportedTier : unsupportedTiersList) {
        log.warn("String_Node_Str" + unsupportedTier.getName() + "String_Node_Str");
      }
      importedApi.removeAvailableTiers(unsupportedTiersList);
    }
  }
  try {
    provider.addAPI(importedApi);
    if (!APIConstants.APIType.WS.toString().equalsIgnoreCase(importedApi.getType())) {
      String swaggerContent=FileUtils.readFileToString(new File(pathToArchive + APIImportExportConstants.SWAGGER_DEFINITION_LOCATION));
      addSwaggerDefinition(importedApi.getId(),swaggerContent);
      Set<URITemplate> uriTemplates=definitionFromSwagger20.getURITemplates(importedApi,swaggerContent);
      importedApi.setUriTemplates(uriTemplates);
      Set<Scope> scopes=definitionFromSwagger20.getScopes(swaggerContent);
      importedApi.setScopes(scopes);
      for (      URITemplate uriTemplate : uriTemplates) {
        Scope scope=uriTemplate.getScope();
        if (scope != null && !(APIUtil.isWhiteListedScope(scope.getKey()))) {
          if (provider.isScopeKeyAssigned(importedApi.getId(),scope.getKey(),PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true))) {
            String errorMessage="String_Node_Str" + scope.getKey() + "String_Node_Str"+ "String_Node_Str";
            log.error(errorMessage);
            throw new APIImportException(errorMessage);
          }
        }
      }
      provider.updateAPI(importedApi);
    }
  }
 catch (  APIManagementException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
catch (  IOException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
catch (  FaultGatewaysException e) {
    String errorMessage="String_Node_Str";
    log.error(errorMessage,e);
    throw new APIImportException(errorMessage,e);
  }
  addAPIImage(pathToArchive,importedApi);
  addAPIDocuments(pathToArchive,importedApi);
  addAPISequences(pathToArchive,importedApi);
  addAPISpecificSequences(pathToArchive,importedApi);
  addAPIWsdl(pathToArchive,importedApi);
}