Program: 115980
Project: 115980
Buggy source:
/** 
 * Verify the existence of the application and add it.
 * @param appDefinition
 * @param ctxt
 * @param userName
 * @param tenantDomain
 * @throws RestAPIException
 */
public static void addApplication(ApplicationBean appDefinition,ConfigurationContext ctxt,String userName,String tenantDomain) throws RestAPIException {
  try {
    if (AutoscalerServiceClient.getInstance().getApplication(appDefinition.getApplicationId()) != null) {
      String msg="String_Node_Str" + appDefinition.getApplicationId();
      throw new RestAPIException(msg);
    }
  }
 catch (  RemoteException e) {
    throw new RestAPIException("String_Node_Str",e);
  }
  ApplicationContext applicationContext=ObjectConverter.convertApplicationDefinitionToStubApplicationContext(appDefinition);
  applicationContext.setTenantId(ApplicationManagementUtil.getTenantId(ctxt));
  applicationContext.setTenantDomain(tenantDomain);
  applicationContext.setTenantAdminUsername(userName);
  if (appDefinition.getProperty() != null) {
    org.apache.stratos.autoscaler.stub.Properties properties=new org.apache.stratos.autoscaler.stub.Properties();
    for (    PropertyBean propertyBean : appDefinition.getProperty()) {
      org.apache.stratos.autoscaler.stub.Property property=new org.apache.stratos.autoscaler.stub.Property();
      property.setName(propertyBean.getName());
      property.setValue(propertyBean.getValue());
      properties.addProperties(property);
    }
    applicationContext.setProperties(properties);
  }
  try {
    AutoscalerServiceClient.getInstance().addApplication(applicationContext);
    Set<String> cartridgeNames;
    Set<String> cartridgeGroupNames;
    StratosManagerServiceClient smServiceClient=getStratosManagerServiceClient();
    List<CartridgeReferenceBean> cartridges=appDefinition.getComponents().getCartridges();
    if (cartridges != null) {
      cartridgeNames=new HashSet<String>();
      for (      CartridgeReferenceBean cartridge : cartridges) {
        cartridgeNames.add(cartridge.getType());
      }
      smServiceClient.addUsedCartridgesInApplications(appDefinition.getApplicationId(),(String[])cartridgeNames.toArray());
    }
    List<GroupReferenceBean> cartridgeGroups=appDefinition.getComponents().getGroups();
    if (cartridgeGroups != null) {
      cartridgeGroupNames=new HashSet<String>();
      for (      GroupReferenceBean cartridgeGroup : cartridgeGroups) {
        cartridgeGroupNames.add(cartridgeGroup.getName());
      }
      smServiceClient.addUsedCartridgeGroupsInApplications(appDefinition.getApplicationId(),(String[])cartridgeGroupNames.toArray());
    }
  }
 catch (  AutoScalerServiceApplicationDefinitionExceptionException e) {
    throw new RestAPIException(e);
  }
catch (  RemoteException e) {
    throw new RestAPIException(e);
  }
}

Fixed version (ground truth):
/** 
 * Verify the existence of the application and add it.
 * @param appDefinition
 * @param ctxt
 * @param userName
 * @param tenantDomain
 * @throws RestAPIException
 */
public static void addApplication(ApplicationBean appDefinition,ConfigurationContext ctxt,String userName,String tenantDomain) throws RestAPIException {
  try {
    if (AutoscalerServiceClient.getInstance().getApplication(appDefinition.getApplicationId()) != null) {
      String msg="String_Node_Str" + appDefinition.getApplicationId();
      throw new RestAPIException(msg);
    }
  }
 catch (  RemoteException e) {
    throw new RestAPIException("String_Node_Str",e);
  }
  ApplicationContext applicationContext=ObjectConverter.convertApplicationDefinitionToStubApplicationContext(appDefinition);
  applicationContext.setTenantId(ApplicationManagementUtil.getTenantId(ctxt));
  applicationContext.setTenantDomain(tenantDomain);
  applicationContext.setTenantAdminUsername(userName);
  if (appDefinition.getProperty() != null) {
    org.apache.stratos.autoscaler.stub.Properties properties=new org.apache.stratos.autoscaler.stub.Properties();
    for (    PropertyBean propertyBean : appDefinition.getProperty()) {
      org.apache.stratos.autoscaler.stub.Property property=new org.apache.stratos.autoscaler.stub.Property();
      property.setName(propertyBean.getName());
      property.setValue(propertyBean.getValue());
      properties.addProperties(property);
    }
    applicationContext.setProperties(properties);
  }
  try {
    AutoscalerServiceClient.getInstance().addApplication(applicationContext);
    String[] cartridgeNames;
    String[] cartridgeGroupNames;
    StratosManagerServiceClient smServiceClient=getStratosManagerServiceClient();
    List<CartridgeReferenceBean> cartridges=appDefinition.getComponents().getCartridges();
    if (cartridges != null) {
      cartridgeNames=new String[cartridges.size()];
      int i=0;
      for (      CartridgeReferenceBean cartridge : cartridges) {
        cartridgeNames[i]=cartridge.getType();
        i++;
      }
      smServiceClient.addUsedCartridgesInApplications(appDefinition.getApplicationId(),cartridgeNames);
    }
    List<GroupReferenceBean> cartridgeGroups=appDefinition.getComponents().getGroups();
    if (cartridgeGroups != null) {
      cartridgeGroupNames=new String[cartridgeGroups.size()];
      int i=0;
      for (      GroupReferenceBean cartridgeGroup : cartridgeGroups) {
        cartridgeGroupNames[i]=cartridgeGroup.getName();
        i++;
      }
      smServiceClient.addUsedCartridgeGroupsInApplications(appDefinition.getApplicationId(),cartridgeGroupNames);
    }
  }
 catch (  AutoScalerServiceApplicationDefinitionExceptionException e) {
    throw new RestAPIException(e);
  }
catch (  RemoteException e) {
    throw new RestAPIException(e);
  }
}