Program: 116735
Project: 116735
Buggy source:
static SubscriptionInfo subscribe(String cartridgeType,String alias,String autoscalingPolicy,String deploymentPolicy,String repoURL,boolean privateRepo,String repoUsername,String repoPassword,String dataCartridgeType,String dataCartridgeAlias,ConfigurationContext configurationContext,String userName,String tenantDomain) throws ADCException, PolicyException, UnregisteredCartridgeException, InvalidCartridgeAliasException, DuplicateCartridgeAliasException, RepositoryRequiredException, AlreadySubscribedException, RepositoryCredentialsRequiredException, InvalidRepositoryException, RepositoryTransportException {
  AutoscalerServiceClient autoscalerServiceClient=getAutoscalerServiceClient();
  CloudControllerServiceClient cloudControllerServiceClient=getCloudControllerServiceClient();
  CartridgeInfo cartridgeInfo;
  try {
    cartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(cartridgeType);
  }
 catch (  Exception e) {
    String msg="String_Node_Str" + cartridgeType;
    log.error(msg,e);
    throw new ADCException(msg,e);
  }
  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" + cartridgeType);
    }
  }
 else {
    CartridgeInfo lbCartridgeInfo;
    String lbCartridgeType=lbConfig.getType();
    try {
      lbCartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
    }
 catch (    Exception e) {
      String msg="String_Node_Str" + cartridgeType;
      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" + cartridgeType);
          }
          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" + cartridgeType + "String_Node_Str"+ clusterIdsVal);
        }
        String[] clusterIds=clusterIdsVal.split("String_Node_Str");
        for (        String clusterId : clusterIds) {
          if (autoscalerServiceClient != null) {
            try {
              autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,deploymentPolicy);
            }
 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" + cartridgeType);
          }
          if (autoscalerServiceClient != null) {
            try {
              DeploymentPolicy[] lbCartridgeDepPolicies=autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
              for (              DeploymentPolicy policy : lbCartridgeDepPolicies) {
                if (deploymentPolicy.equals(policy.getId())) {
                  if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
                    String lbAlias="String_Node_Str" + new Random().nextInt();
                    lbCartridgeInfo.addProperties(property);
                    subscribeToLb(lbCartridgeType,lbAlias,lbCartridgeInfo.getDefaultAutoscalingPolicy(),deploymentPolicy,configurationContext,userName,tenantDomain,lbCartridgeInfo.getProperties());
                  }
                }
              }
            }
 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" + cartridgeType);
            }
            if (autoscalerServiceClient != null) {
              try {
                DeploymentPolicy[] lbCartridgeDepPolicies=autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
                for (                DeploymentPolicy policy : lbCartridgeDepPolicies) {
                  if (deploymentPolicy.equals(policy.getId())) {
                    if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,deploymentPolicy)) {
                      String lbAlias="String_Node_Str" + cartridgeType + new Random().nextInt();
                      lbCartridgeInfo.addProperties(property);
                      subscribeToLb(lbCartridgeType,lbAlias,lbCartridgeInfo.getDefaultAutoscalingPolicy(),deploymentPolicy,configurationContext,userName,tenantDomain,lbCartridgeInfo.getProperties());
                    }
                  }
                }
              }
 catch (              Exception ex) {
                log.error(ex.getMessage(),ex);
              }
            }
            lbRefProp.add(property);
            break;
          }
        }
      }
    }
  }
  CartridgeSubscription cartridgeSubscription=cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(cartridgeType,alias.trim(),autoscalingPolicy,deploymentPolicy,tenantDomain,ApplicationManagementUtil.getTenantId(configurationContext),userName,"String_Node_Str",repoURL,privateRepo,repoUsername,repoPassword,lbRefProp.toArray(new Property[0]));
  if (dataCartridgeAlias != null && !dataCartridgeAlias.trim().isEmpty()) {
  }
  SubscriptionInfo registerCartridgeSubscription=cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription);
  return registerCartridgeSubscription;
}

Fixed version (ground truth):
static SubscriptionInfo subscribe(String cartridgeType,String alias,String autoscalingPolicy,String deploymentPolicy,String repoURL,boolean privateRepo,String repoUsername,String repoPassword,String dataCartridgeType,String dataCartridgeAlias,ConfigurationContext configurationContext,String userName,String tenantDomain) throws ADCException, PolicyException, UnregisteredCartridgeException, InvalidCartridgeAliasException, DuplicateCartridgeAliasException, RepositoryRequiredException, AlreadySubscribedException, RepositoryCredentialsRequiredException, InvalidRepositoryException, RepositoryTransportException {
  AutoscalerServiceClient autoscalerServiceClient=getAutoscalerServiceClient();
  CloudControllerServiceClient cloudControllerServiceClient=getCloudControllerServiceClient();
  CartridgeInfo cartridgeInfo;
  try {
    cartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(cartridgeType);
  }
 catch (  Exception e) {
    String msg="String_Node_Str" + cartridgeType;
    log.error(msg,e);
    throw new ADCException(msg,e);
  }
  if (cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
    log.info("String_Node_Str");
    CartridgeSubscription cartridgeSubscription=cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(cartridgeType,alias,autoscalingPolicy,deploymentPolicy,tenantDomain,ApplicationManagementUtil.getTenantId(configurationContext),userName,"String_Node_Str",repoURL,false,repoUsername,repoPassword,null);
    log.info("String_Node_Str");
    return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription);
  }
  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" + cartridgeType);
    }
  }
 else {
    CartridgeInfo lbCartridgeInfo;
    String lbCartridgeType=lbConfig.getType();
    try {
      lbCartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
    }
 catch (    Exception e) {
      String msg="String_Node_Str" + cartridgeType;
      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" + cartridgeType);
          }
          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" + cartridgeType + "String_Node_Str"+ clusterIdsVal);
        }
        String[] clusterIds=clusterIdsVal.split("String_Node_Str");
        for (        String clusterId : clusterIds) {
          if (autoscalerServiceClient != null) {
            try {
              autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,deploymentPolicy);
            }
 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" + cartridgeType);
          }
          if (autoscalerServiceClient != null) {
            try {
              DeploymentPolicy[] lbCartridgeDepPolicies=autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
              for (              DeploymentPolicy policy : lbCartridgeDepPolicies) {
                if (deploymentPolicy.equals(policy.getId())) {
                  if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
                    String lbAlias="String_Node_Str" + new Random().nextInt();
                    lbCartridgeInfo.addProperties(property);
                    subscribeToLb(lbCartridgeType,lbAlias,lbCartridgeInfo.getDefaultAutoscalingPolicy(),deploymentPolicy,configurationContext,userName,tenantDomain,lbCartridgeInfo.getProperties());
                  }
                }
              }
            }
 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" + cartridgeType);
            }
            if (autoscalerServiceClient != null) {
              try {
                DeploymentPolicy[] lbCartridgeDepPolicies=autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
                for (                DeploymentPolicy policy : lbCartridgeDepPolicies) {
                  if (deploymentPolicy.equals(policy.getId())) {
                    if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,deploymentPolicy)) {
                      String lbAlias="String_Node_Str" + cartridgeType + new Random().nextInt();
                      lbCartridgeInfo.addProperties(property);
                      subscribeToLb(lbCartridgeType,lbAlias,lbCartridgeInfo.getDefaultAutoscalingPolicy(),deploymentPolicy,configurationContext,userName,tenantDomain,lbCartridgeInfo.getProperties());
                    }
                  }
                }
              }
 catch (              Exception ex) {
                log.error(ex.getMessage(),ex);
              }
            }
            lbRefProp.add(property);
            break;
          }
        }
      }
    }
  }
  CartridgeSubscription cartridgeSubscription=cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(cartridgeType,alias.trim(),autoscalingPolicy,deploymentPolicy,tenantDomain,ApplicationManagementUtil.getTenantId(configurationContext),userName,"String_Node_Str",repoURL,privateRepo,repoUsername,repoPassword,lbRefProp.toArray(new Property[0]));
  if (dataCartridgeAlias != null && !dataCartridgeAlias.trim().isEmpty()) {
  }
  SubscriptionInfo registerCartridgeSubscription=cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription);
  return registerCartridgeSubscription;
}