Program: 115689
Project: 115689
Buggy source:
/** 
 * Add a Service Group
 * @param serviceGroupDefinition serviceGroupDefinition
 * @throws InvalidCartridgeGroupDefinitionException
 * @throws RestAPIException
 */
public static void addServiceGroup(CartridgeGroupBean serviceGroupDefinition) throws InvalidCartridgeGroupDefinitionException, RestAPIException {
  try {
    if (serviceGroupDefinition == null) {
      throw new RuntimeException("String_Node_Str");
    }
    List<String> cartridgeTypes=new ArrayList<String>();
    String[] cartridgeNames=null;
    List<String> groupNames;
    String[] cartridgeGroupNames;
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + serviceGroupDefinition.getName());
    }
    findCartridgesInGroupBean(serviceGroupDefinition,cartridgeTypes);
    validateCartridgeDuplicationInGroupDefinition(serviceGroupDefinition);
    validateGroupDuplicationInGroupDefinition(serviceGroupDefinition);
    CloudControllerServiceClient ccServiceClient=getCloudControllerServiceClient();
    cartridgeNames=new String[cartridgeTypes.size()];
    int j=0;
    for (    String cartridgeType : cartridgeTypes) {
      try {
        if (ccServiceClient.getCartridge(cartridgeType) == null) {
          log.error("String_Node_Str" + cartridgeType);
          throw new RestAPIException("String_Node_Str" + cartridgeType);
        }
 else {
          cartridgeNames[j]=cartridgeType;
          j++;
        }
      }
 catch (      RemoteException e) {
        String message="String_Node_Str" + serviceGroupDefinition.getName();
        log.error(message,e);
        throw new RestAPIException(message,e);
      }
catch (      CloudControllerServiceCartridgeNotFoundExceptionException e) {
        throw new RestAPIException(e);
      }
    }
    if (serviceGroupDefinition.getGroups() != null) {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + serviceGroupDefinition.getName());
      }
      List<CartridgeGroupBean> groupDefinitions=serviceGroupDefinition.getGroups();
      groupNames=new ArrayList<String>();
      cartridgeGroupNames=new String[groupDefinitions.size()];
      int i=0;
      for (      CartridgeGroupBean groupList : groupDefinitions) {
        groupNames.add(groupList.getName());
        cartridgeGroupNames[i]=groupList.getName();
        i++;
      }
      Set<String> duplicates=findDuplicates(groupNames);
      if (duplicates.size() > 0) {
        StringBuilder duplicatesOutput=new StringBuilder();
        for (        String dup : duplicates) {
          duplicatesOutput.append(dup).append("String_Node_Str");
        }
        if (log.isDebugEnabled()) {
          log.debug("String_Node_Str" + duplicatesOutput.toString());
        }
        throw new RestAPIException("String_Node_Str" + duplicatesOutput.toString());
      }
    }
    ServiceGroup serviceGroup=ObjectConverter.convertServiceGroupDefinitionToASStubServiceGroup(serviceGroupDefinition);
    AutoscalerServiceClient asServiceClient=getAutoscalerServiceClient();
    asServiceClient.addServiceGroup(serviceGroup);
    StratosManagerServiceClient smServiceClient=getStratosManagerServiceClient();
    smServiceClient.addUsedCartridgesInCartridgeGroups(serviceGroupDefinition.getName(),cartridgeNames);
  }
 catch (  InvalidCartridgeGroupDefinitionException e) {
    throw e;
  }
catch (  Exception e) {
    String message="String_Node_Str";
    log.error(message,e);
    throw new RestAPIException(message,e);
  }
}

Fixed version (ground truth):
/** 
 * Add a Service Group
 * @param serviceGroupDefinition serviceGroupDefinition
 * @throws InvalidCartridgeGroupDefinitionException
 * @throws RestAPIException
 */
public static void addServiceGroup(CartridgeGroupBean serviceGroupDefinition) throws InvalidCartridgeGroupDefinitionException, RestAPIException {
  try {
    if (serviceGroupDefinition == null) {
      throw new RuntimeException("String_Node_Str");
    }
    List<String> cartridgeTypes=new ArrayList<String>();
    String[] cartridgeNames=null;
    List<String> groupNames;
    String[] cartridgeGroupNames;
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + serviceGroupDefinition.getName());
    }
    findCartridgesInGroupBean(serviceGroupDefinition,cartridgeTypes);
    validateCartridgeDuplicationInGroupDefinition(serviceGroupDefinition);
    validateGroupDuplicationInGroupDefinition(serviceGroupDefinition);
    CloudControllerServiceClient ccServiceClient=getCloudControllerServiceClient();
    cartridgeNames=new String[cartridgeTypes.size()];
    int j=0;
    for (    String cartridgeType : cartridgeTypes) {
      try {
        if (ccServiceClient.getCartridge(cartridgeType) == null) {
          log.error("String_Node_Str" + cartridgeType);
          throw new RestAPIException("String_Node_Str" + cartridgeType);
        }
 else {
          cartridgeNames[j]=cartridgeType;
          j++;
        }
      }
 catch (      RemoteException e) {
        String message="String_Node_Str" + serviceGroupDefinition.getName();
        log.error(message,e);
        throw new RestAPIException(message,e);
      }
catch (      CloudControllerServiceCartridgeNotFoundExceptionException e) {
        String message="String_Node_Str";
        log.error(message,e);
        throw new RestAPIException(message,e);
      }
    }
    if (serviceGroupDefinition.getGroups() != null) {
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + serviceGroupDefinition.getName());
      }
      List<CartridgeGroupBean> groupDefinitions=serviceGroupDefinition.getGroups();
      groupNames=new ArrayList<String>();
      cartridgeGroupNames=new String[groupDefinitions.size()];
      int i=0;
      for (      CartridgeGroupBean groupList : groupDefinitions) {
        groupNames.add(groupList.getName());
        cartridgeGroupNames[i]=groupList.getName();
        i++;
      }
      Set<String> duplicates=findDuplicates(groupNames);
      if (duplicates.size() > 0) {
        StringBuilder duplicatesOutput=new StringBuilder();
        for (        String dup : duplicates) {
          duplicatesOutput.append(dup).append("String_Node_Str");
        }
        if (log.isDebugEnabled()) {
          log.debug("String_Node_Str" + duplicatesOutput.toString());
        }
        throw new RestAPIException("String_Node_Str" + duplicatesOutput.toString());
      }
    }
    ServiceGroup serviceGroup=ObjectConverter.convertServiceGroupDefinitionToASStubServiceGroup(serviceGroupDefinition);
    AutoscalerServiceClient asServiceClient=getAutoscalerServiceClient();
    asServiceClient.addServiceGroup(serviceGroup);
    StratosManagerServiceClient smServiceClient=getStratosManagerServiceClient();
    smServiceClient.addUsedCartridgesInCartridgeGroups(serviceGroupDefinition.getName(),cartridgeNames);
  }
 catch (  InvalidCartridgeGroupDefinitionException e) {
    throw e;
  }
catch (  Exception e) {
    String message="String_Node_Str";
    log.error(message,e);
    throw new RestAPIException(message,e);
  }
}