Program: 114801
Project: 114801
Buggy source:
/** 
 * This method is used to migrate rxt This adds three new attributes to the api rxt
 * @throws APIMigrationException
 */
void rxtMigration() throws APIMigrationException {
  log.info("String_Node_Str" + Constants.VERSION_1_9 + "String_Node_Str");
  boolean isTenantFlowStarted=false;
  for (  Tenant tenant : getTenantsArray()) {
    log.debug("String_Node_Str" + tenant.getId() + '('+ tenant.getDomain()+ ')');
    try {
      PrivilegedCarbonContext.startTenantFlow();
      isTenantFlowStarted=true;
      PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain(),true);
      PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId(),true);
      String adminName=ServiceHolder.getRealmService().getTenantUserRealm(tenant.getId()).getRealmConfiguration().getAdminUserName();
      log.debug("String_Node_Str" + adminName);
      ServiceHolder.getTenantRegLoader().loadTenantRegistry(tenant.getId());
      Registry registry=ServiceHolder.getRegistryService().getGovernanceUserRegistry(adminName,tenant.getId());
      GenericArtifactManager artifactManager=APIUtil.getArtifactManager(registry,APIConstants.API_KEY);
      if (artifactManager != null) {
        GovernanceUtils.loadGovernanceArtifacts((UserRegistry)registry);
        GenericArtifact[] artifacts=artifactManager.getAllGenericArtifacts();
        for (        GenericArtifact artifact : artifacts) {
          API api=APIUtil.getAPI(artifact,registry);
          if (api == null) {
            log.error("String_Node_Str" + artifact.getAttribute("String_Node_Str") + '-'+ artifact.getAttribute("String_Node_Str")+ '-'+ artifact.getAttribute("String_Node_Str")+ "String_Node_Str"+ tenant.getId()+ '('+ tenant.getDomain()+ "String_Node_Str");
            continue;
          }
          APIIdentifier apiIdentifier=api.getId();
          String apiVersion=apiIdentifier.getVersion();
          if (!(api.getContext().endsWith(RegistryConstants.PATH_SEPARATOR + apiVersion))) {
            artifact.setAttribute("String_Node_Str",api.getContext() + RegistryConstants.PATH_SEPARATOR + apiVersion);
          }
          artifact.setAttribute("String_Node_Str",api.getContext() + RegistryConstants.PATH_SEPARATOR + "String_Node_Str");
          artifact.setAttribute("String_Node_Str","String_Node_Str");
          artifact.setAttribute("String_Node_Str","String_Node_Str");
          artifactManager.updateGenericArtifact(artifact);
        }
      }
 else {
        log.debug("String_Node_Str" + tenant.getId() + '('+ tenant.getDomain()+ ')');
      }
    }
 catch (    APIManagementException e) {
      ResourceUtil.handleException("String_Node_Str",e);
    }
catch (    RegistryException e) {
      ResourceUtil.handleException("String_Node_Str",e);
    }
catch (    UserStoreException e) {
      ResourceUtil.handleException("String_Node_Str",e);
    }
 finally {
      if (isTenantFlowStarted) {
        PrivilegedCarbonContext.endTenantFlow();
      }
    }
    log.debug("String_Node_Str" + tenant.getId() + '('+ tenant.getDomain()+ ')');
  }
  log.info("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * This method is used to migrate rxt This adds three new attributes to the api rxt
 * @throws APIMigrationException
 */
void rxtMigration() throws APIMigrationException {
  log.info("String_Node_Str" + Constants.VERSION_1_9 + "String_Node_Str");
  boolean isTenantFlowStarted=false;
  for (  Tenant tenant : getTenantsArray()) {
    log.debug("String_Node_Str" + tenant.getId() + '('+ tenant.getDomain()+ ')');
    try {
      PrivilegedCarbonContext.startTenantFlow();
      isTenantFlowStarted=true;
      PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain(),true);
      PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId(),true);
      String adminName=ServiceHolder.getRealmService().getTenantUserRealm(tenant.getId()).getRealmConfiguration().getAdminUserName();
      log.debug("String_Node_Str" + adminName);
      ServiceHolder.getTenantRegLoader().loadTenantRegistry(tenant.getId());
      Registry registry=ServiceHolder.getRegistryService().getGovernanceUserRegistry(adminName,tenant.getId());
      GenericArtifactManager artifactManager=APIUtil.getArtifactManager(registry,APIConstants.API_KEY);
      if (artifactManager != null) {
        GovernanceUtils.loadGovernanceArtifacts((UserRegistry)registry);
        GenericArtifact[] artifacts=artifactManager.getAllGenericArtifacts();
        for (        GenericArtifact artifact : artifacts) {
          try {
            API api=APIUtil.getAPI(artifact,registry);
            if (api == null) {
              log.error("String_Node_Str" + artifact.getAttribute("String_Node_Str") + '-'+ artifact.getAttribute("String_Node_Str")+ '-'+ artifact.getAttribute("String_Node_Str")+ "String_Node_Str"+ tenant.getId()+ '('+ tenant.getDomain()+ "String_Node_Str");
              continue;
            }
            APIIdentifier apiIdentifier=api.getId();
            String apiVersion=apiIdentifier.getVersion();
            if (!(api.getContext().endsWith(RegistryConstants.PATH_SEPARATOR + apiVersion))) {
              artifact.setAttribute("String_Node_Str",api.getContext() + RegistryConstants.PATH_SEPARATOR + apiVersion);
            }
            artifact.setAttribute("String_Node_Str",api.getContext() + RegistryConstants.PATH_SEPARATOR + "String_Node_Str");
            artifact.setAttribute("String_Node_Str","String_Node_Str");
            artifact.setAttribute("String_Node_Str","String_Node_Str");
            artifactManager.updateGenericArtifact(artifact);
          }
 catch (          Exception e) {
            log.error("String_Node_Str" + artifact.getAttribute("String_Node_Str") + '-'+ artifact.getAttribute("String_Node_Str")+ '-'+ artifact.getAttribute("String_Node_Str"),e);
          }
        }
      }
 else {
        log.debug("String_Node_Str" + tenant.getId() + '('+ tenant.getDomain()+ ')');
      }
    }
 catch (    APIManagementException e) {
      ResourceUtil.handleException("String_Node_Str",e);
    }
catch (    RegistryException e) {
      ResourceUtil.handleException("String_Node_Str",e);
    }
catch (    UserStoreException e) {
      ResourceUtil.handleException("String_Node_Str",e);
    }
 finally {
      if (isTenantFlowStarted) {
        PrivilegedCarbonContext.endTenantFlow();
      }
    }
    log.debug("String_Node_Str" + tenant.getId() + '('+ tenant.getDomain()+ ')');
  }
  log.info("String_Node_Str");
}