Program: 115480
Project: 115480
Buggy source:
/** 
 * Add a Service Group
 * @param serviceGroupDefinition serviceGroupDefinition
 * @throws InvalidCartridgeGroupDefinitionException
 * @throws RestAPIException
 */
public static void addCartridgeGroup(CartridgeGroupBean serviceGroupDefinition,String cartridgeGroupUuid,int tenantId) throws InvalidCartridgeGroupDefinitionException, ServiceGroupDefinitionException, RestAPIException, CloudControllerServiceCartridgeNotFoundExceptionException, AutoscalerServiceInvalidServiceGroupExceptionException {
  if (serviceGroupDefinition == null) {
    throw new RuntimeException("String_Node_Str");
  }
  List<String> cartridgeTypes=new ArrayList<String>();
  String[] cartridgeUuids;
  List<String> groupNames;
  String[] cartridgeGroupNames;
  if (log.isDebugEnabled()) {
    log.debug(String.format("String_Node_Str" + "String_Node_Str",tenantId,cartridgeGroupUuid,serviceGroupDefinition.getName()));
  }
  ServiceGroup serviceGroup=ObjectConverter.convertServiceGroupDefinitionToASStubServiceGroup(serviceGroupDefinition,UUID.randomUUID().toString(),tenantId);
  try {
    findCartridgesInGroupBean(serviceGroup,cartridgeTypes);
  }
 catch (  RemoteException e) {
    throw new RestAPIException(e.getMessage());
  }
  validateCartridgeDuplicationInGroupDefinition(serviceGroupDefinition);
  try {
    validateGroupDuplicationInGroupDefinition(serviceGroupDefinition);
  }
 catch (  RemoteException e) {
    String message=String.format("String_Node_Str" + "String_Node_Str",tenantId,cartridgeGroupUuid,serviceGroupDefinition.getName());
    log.error(message,e);
    throw new RestAPIException(message,e);
  }
  cartridgeUuids=new String[cartridgeTypes.size()];
  int j=0;
  for (  String cartridgeUuid : cartridgeTypes) {
    cartridgeUuids[j]=cartridgeUuid;
    j++;
  }
  if (serviceGroupDefinition.getGroups() != null) {
    if (log.isDebugEnabled()) {
      log.debug(String.format("String_Node_Str" + "String_Node_Str",tenantId,cartridgeGroupUuid,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 InvalidCartridgeGroupDefinitionException("String_Node_Str" + "String_Node_Str" + duplicatesOutput.toString());
    }
  }
  AutoscalerServiceClient asServiceClient=getAutoscalerServiceClient();
  try {
    asServiceClient.addServiceGroup(serviceGroup);
    StratosManagerServiceClient smServiceClient=getStratosManagerServiceClient();
    smServiceClient.addUsedCartridgesInCartridgeGroups(serviceGroup.getUuid(),cartridgeUuids);
  }
 catch (  RemoteException e) {
    String message=String.format("String_Node_Str",serviceGroupDefinition.getName());
    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 addCartridgeGroup(CartridgeGroupBean serviceGroupDefinition,String cartridgeGroupUuid,int tenantId) throws InvalidCartridgeGroupDefinitionException, ServiceGroupDefinitionException, RestAPIException, CloudControllerServiceCartridgeNotFoundExceptionException, AutoscalerServiceInvalidServiceGroupExceptionException {
  if (serviceGroupDefinition == null) {
    throw new RuntimeException("String_Node_Str");
  }
  List<String> cartridgeTypes=new ArrayList<String>();
  String[] cartridgeUuids;
  List<String> groupNames;
  String[] cartridgeGroupNames;
  if (log.isDebugEnabled()) {
    log.debug(String.format("String_Node_Str" + "String_Node_Str",tenantId,cartridgeGroupUuid,serviceGroupDefinition.getName()));
  }
  ServiceGroup serviceGroup=ObjectConverter.convertServiceGroupDefinitionToASStubServiceGroup(serviceGroupDefinition,cartridgeGroupUuid,tenantId);
  try {
    findCartridgesInGroupBean(serviceGroup,cartridgeTypes);
  }
 catch (  RemoteException e) {
    throw new RestAPIException(e.getMessage());
  }
  validateCartridgeDuplicationInGroupDefinition(serviceGroupDefinition);
  try {
    validateGroupDuplicationInGroupDefinition(serviceGroupDefinition);
  }
 catch (  RemoteException e) {
    String message=String.format("String_Node_Str" + "String_Node_Str",tenantId,cartridgeGroupUuid,serviceGroupDefinition.getName());
    log.error(message,e);
    throw new RestAPIException(message,e);
  }
  cartridgeUuids=new String[cartridgeTypes.size()];
  int j=0;
  for (  String cartridgeUuid : cartridgeTypes) {
    cartridgeUuids[j]=cartridgeUuid;
    j++;
  }
  if (serviceGroupDefinition.getGroups() != null) {
    if (log.isDebugEnabled()) {
      log.debug(String.format("String_Node_Str" + "String_Node_Str",tenantId,cartridgeGroupUuid,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 InvalidCartridgeGroupDefinitionException("String_Node_Str" + "String_Node_Str" + duplicatesOutput.toString());
    }
  }
  AutoscalerServiceClient asServiceClient=getAutoscalerServiceClient();
  try {
    asServiceClient.addServiceGroup(serviceGroup);
    StratosManagerServiceClient smServiceClient=getStratosManagerServiceClient();
    smServiceClient.addUsedCartridgesInCartridgeGroups(serviceGroup.getUuid(),cartridgeUuids);
  }
 catch (  RemoteException e) {
    String message=String.format("String_Node_Str",serviceGroupDefinition.getName());
    log.error(message,e);
    throw new RestAPIException(message,e);
  }
}