Program: 116696
Project: 116696
Buggy source:
public Service deployService(String type,String autoscalingPolicyName,String deploymentPolicyName,int tenantId,String tenantRange,String tenantDomain,String userName) throws ADCException, UnregisteredCartridgeException, ServiceAlreadyDeployedException {
  DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager=new DataInsertionAndRetrievalManager();
  Service deployedService;
  try {
    deployedService=dataInsertionAndRetrievalManager.getService(type);
  }
 catch (  PersistenceManagerException e) {
    String errorMsg="String_Node_Str";
    log.error(errorMsg,e);
    throw new ADCException(errorMsg,e);
  }
  if (deployedService != null) {
    String errorMsg="String_Node_Str" + type;
    log.error(errorMsg);
    throw new ServiceAlreadyDeployedException(errorMsg,type);
  }
  CartridgeInfo cartridgeInfo;
  try {
    cartridgeInfo=CloudControllerServiceClient.getServiceClient().getCartridgeInfo(type);
  }
 catch (  UnregisteredCartridgeException e) {
    String message=type + "String_Node_Str";
    log.error(message);
    throw e;
  }
catch (  Exception e) {
    String message="String_Node_Str" + type;
    log.error(message,e);
    throw new ADCException(message,e);
  }
  if (!cartridgeInfo.getMultiTenant()) {
    String errorMsg="String_Node_Str" + type + "String_Node_Str";
    log.error(errorMsg);
    throw new ADCException(errorMsg);
  }
  List<Property> lbRefProp=new ArrayList<Property>();
  LoadbalancerConfig lbConfig=cartridgeInfo.getLbConfig();
  if (lbConfig == null || lbConfig.getProperties() == null) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + "String_Node_Str" + type);
    }
  }
 else {
    Service lbService;
    CartridgeInfo lbCartridgeInfo;
    String lbCartridgeType=lbConfig.getType();
    try {
      lbCartridgeInfo=CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
    }
 catch (    Exception e) {
      String msg="String_Node_Str" + type;
      log.error(msg,e);
      throw new ADCException(msg,e);
    }
    Properties lbReferenceProperties=lbConfig.getProperties();
    Property property=new Property();
    property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
    for (    org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
      String name=prop.getName();
      String value=prop.getValue();
      if (Constants.NO_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + type);
          }
          property.setValue(name);
          lbRefProp.add(property);
          break;
        }
      }
 else       if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
        String clusterIdsVal=value;
        if (log.isDebugEnabled()) {
          log.debug("String_Node_Str" + "String_Node_Str" + type + "String_Node_Str"+ clusterIdsVal);
        }
        String[] clusterIds=clusterIdsVal.split("String_Node_Str");
        for (        String clusterId : clusterIds) {
          try {
            AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId,deploymentPolicyName);
          }
 catch (          Exception ex) {
            log.error(ex.getMessage(),ex);
          }
        }
        property.setValue(name);
        lbRefProp.add(property);
        break;
      }
 else       if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          property.setValue(name);
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + type);
          }
          try {
            DeploymentPolicy[] lbCartridgeDepPolicies=AutoscalerServiceClient.getServiceClient().getDeploymentPolicies(lbCartridgeType);
            for (            DeploymentPolicy policy : lbCartridgeDepPolicies) {
              if (deploymentPolicyName.equals(policy.getId())) {
                if (!AutoscalerServiceClient.getServiceClient().checkDefaultLBExistenceAgainstPolicy(deploymentPolicyName)) {
                  lbCartridgeInfo.addProperties(property);
                  lbService=new MultiTenantLBService(lbCartridgeType,lbCartridgeInfo.getDefaultAutoscalingPolicy(),deploymentPolicyName,tenantId,lbCartridgeInfo,tenantRange);
                  lbService.deploy();
                }
              }
            }
          }
 catch (          Exception ex) {
            log.error(ex.getMessage(),ex);
          }
          lbRefProp.add(property);
          break;
        }
 else         if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
          if ("String_Node_Str".equals(value)) {
            property.setValue(name);
            if (log.isDebugEnabled()) {
              log.debug("String_Node_Str" + "String_Node_Str" + type);
            }
            try {
              DeploymentPolicy[] lbCartridgeDepPolicies=AutoscalerServiceClient.getServiceClient().getDeploymentPolicies(lbCartridgeType);
              for (              DeploymentPolicy policy : lbCartridgeDepPolicies) {
                if (deploymentPolicyName.equals(policy.getId())) {
                  if (!AutoscalerServiceClient.getServiceClient().checkServiceLBExistenceAgainstPolicy(type,deploymentPolicyName)) {
                    lbCartridgeInfo.addProperties(property);
                    lbService=new MultiTenantLBService(lbCartridgeType,lbCartridgeInfo.getDefaultAutoscalingPolicy(),deploymentPolicyName,tenantId,lbCartridgeInfo,tenantRange);
                    lbService.deploy();
                  }
                }
              }
            }
 catch (            Exception ex) {
              log.error(ex.getMessage(),ex);
            }
            lbRefProp.add(property);
            break;
          }
        }
      }
    }
  }
  Service service=new MultiTenantService(type,autoscalingPolicyName,deploymentPolicyName,tenantId,cartridgeInfo,tenantRange);
  service.deploy();
  try {
    dataInsertionAndRetrievalManager.persistService(service);
  }
 catch (  PersistenceManagerException e) {
    String errorMsg="String_Node_Str";
    log.error(errorMsg,e);
    throw new ADCException(errorMsg,e);
  }
  return service;
}

Fixed version (ground truth):
public Service deployService(String type,String autoscalingPolicyName,String deploymentPolicyName,int tenantId,String tenantRange,String tenantDomain,String userName) throws ADCException, UnregisteredCartridgeException, ServiceAlreadyDeployedException {
  DataInsertionAndRetrievalManager dataInsertionAndRetrievalManager=new DataInsertionAndRetrievalManager();
  Service deployedService;
  try {
    deployedService=dataInsertionAndRetrievalManager.getService(type);
  }
 catch (  PersistenceManagerException e) {
    String errorMsg="String_Node_Str";
    log.error(errorMsg,e);
    throw new ADCException(errorMsg,e);
  }
  if (deployedService != null) {
    String errorMsg="String_Node_Str" + type;
    log.error(errorMsg);
    throw new ServiceAlreadyDeployedException(errorMsg,type);
  }
  CartridgeInfo cartridgeInfo;
  try {
    cartridgeInfo=CloudControllerServiceClient.getServiceClient().getCartridgeInfo(type);
  }
 catch (  UnregisteredCartridgeException e) {
    String message=type + "String_Node_Str";
    log.error(message);
    throw e;
  }
catch (  Exception e) {
    String message="String_Node_Str" + type;
    log.error(message,e);
    throw new ADCException(message,e);
  }
  if (!cartridgeInfo.getMultiTenant()) {
    String errorMsg="String_Node_Str" + type + "String_Node_Str";
    log.error(errorMsg);
    throw new ADCException(errorMsg);
  }
  List<Property> lbRefProp=new ArrayList<Property>();
  LoadbalancerConfig lbConfig=cartridgeInfo.getLbConfig();
  if (lbConfig == null || lbConfig.getProperties() == null) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + "String_Node_Str" + type);
    }
  }
 else {
    Service lbService;
    CartridgeInfo lbCartridgeInfo;
    String lbCartridgeType=lbConfig.getType();
    try {
      lbCartridgeInfo=CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
    }
 catch (    Exception e) {
      String msg="String_Node_Str" + type;
      log.error(msg,e);
      throw new ADCException(msg,e);
    }
    Properties lbReferenceProperties=lbConfig.getProperties();
    Property property=new Property();
    property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
    for (    org.apache.stratos.cloud.controller.pojo.Property prop : lbReferenceProperties.getProperties()) {
      String name=prop.getName();
      String value=prop.getValue();
      if (Constants.NO_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + type);
          }
          property.setValue(name);
          lbRefProp.add(property);
          break;
        }
      }
 else       if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
        String clusterIdsVal=value;
        if (log.isDebugEnabled()) {
          log.debug("String_Node_Str" + "String_Node_Str" + type + "String_Node_Str"+ clusterIdsVal);
        }
        String[] clusterIds=clusterIdsVal.split("String_Node_Str");
        for (        String clusterId : clusterIds) {
          try {
            AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId,deploymentPolicyName);
          }
 catch (          Exception ex) {
            log.error(ex.getMessage(),ex);
          }
        }
        property.setValue(name);
        lbRefProp.add(property);
        break;
      }
 else       if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          property.setValue(name);
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + type);
          }
          try {
            DeploymentPolicy[] lbCartridgeDepPolicies=AutoscalerServiceClient.getServiceClient().getDeploymentPolicies(lbCartridgeType);
            for (            DeploymentPolicy policy : lbCartridgeDepPolicies) {
              if (deploymentPolicyName.equals(policy.getId())) {
                if (!AutoscalerServiceClient.getServiceClient().checkDefaultLBExistenceAgainstPolicy(deploymentPolicyName)) {
                  lbService=new MultiTenantLBService(lbCartridgeType,lbCartridgeInfo.getDefaultAutoscalingPolicy(),deploymentPolicyName,tenantId,lbCartridgeInfo,tenantRange);
                  Properties lbDeploymentProperties=new Properties();
                  Property[] cartridgeInfoProps=lbCartridgeInfo.getProperties();
                  if (cartridgeInfoProps != null && cartridgeInfoProps.length > 0) {
                    lbDeploymentProperties.setProperties(combine(lbCartridgeInfo.getProperties(),new Property[]{property}));
                  }
 else {
                    lbDeploymentProperties.setProperties(new Property[]{property});
                  }
                  lbService.deploy(lbDeploymentProperties);
                  persist(lbService);
                }
              }
            }
          }
 catch (          Exception ex) {
            log.error(ex.getMessage(),ex);
          }
          lbRefProp.add(property);
          break;
        }
      }
 else       if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          property.setValue(name);
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + type);
          }
          Property loadBalancedServiceTypeProperty=new Property();
          loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
          loadBalancedServiceTypeProperty.setValue(type);
          try {
            DeploymentPolicy[] lbCartridgeDepPolicies=AutoscalerServiceClient.getServiceClient().getDeploymentPolicies(lbCartridgeType);
            for (            DeploymentPolicy policy : lbCartridgeDepPolicies) {
              if (deploymentPolicyName.equals(policy.getId())) {
                if (!AutoscalerServiceClient.getServiceClient().checkServiceLBExistenceAgainstPolicy(type,deploymentPolicyName)) {
                  lbCartridgeInfo.addProperties(property);
                  lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
                  lbService=new MultiTenantLBService(lbCartridgeType,lbCartridgeInfo.getDefaultAutoscalingPolicy(),deploymentPolicyName,tenantId,lbCartridgeInfo,tenantRange);
                  Properties lbDeploymentProperties=new Properties();
                  Property[] cartridgeInfoProps=lbCartridgeInfo.getProperties();
                  if (cartridgeInfoProps != null && cartridgeInfoProps.length > 0) {
                    lbDeploymentProperties.setProperties(combine(lbCartridgeInfo.getProperties(),new Property[]{property,loadBalancedServiceTypeProperty}));
                  }
 else {
                    lbDeploymentProperties.setProperties(new Property[]{property,loadBalancedServiceTypeProperty});
                  }
                  lbService.deploy(lbDeploymentProperties);
                  persist(lbService);
                }
              }
            }
          }
 catch (          Exception ex) {
            log.error(ex.getMessage(),ex);
          }
          lbRefProp.add(property);
          break;
        }
      }
    }
  }
  Service service=new MultiTenantService(type,autoscalingPolicyName,deploymentPolicyName,tenantId,cartridgeInfo,tenantRange);
  Properties serviceDeploymentProperties=new Properties();
  serviceDeploymentProperties.setProperties(lbRefProp.toArray(new Property[0]));
  service.deploy(serviceDeploymentProperties);
  persist(service);
  return service;
}