Program: 115781
Project: 115781
Buggy source:
private boolean createInstanceAndStartDependency(Application application) throws TopologyInConsistentException, PolicyValidationException {
  boolean initialStartup=true;
  List<String> instanceIds=new ArrayList<String>();
  String instanceId;
  ApplicationPolicy applicationPolicy=PolicyManager.getInstance().getApplicationPolicy(application.getApplicationPolicyId());
  if (applicationPolicy == null) {
    String msg=String.format("String_Node_Str",appId);
    log.error(msg);
    throw new RuntimeException(msg);
  }
  NetworkPartitionAlgorithmContext algorithmContext=AutoscalerContext.getInstance().getNetworkPartitionAlgorithmContext(appId);
  if (algorithmContext == null) {
    String msg=String.format("String_Node_Str",appId);
    log.error(msg);
    throw new RuntimeException(msg);
  }
  String networkPartitionAlgorithmName=applicationPolicy.getAlgorithm();
  if (log.isDebugEnabled()) {
    String msg=String.format("String_Node_Str",networkPartitionAlgorithmName,appId);
    log.debug(msg);
  }
  NetworkPartitionAlgorithm algorithm=getNetworkPartitionAlgorithm(networkPartitionAlgorithmName);
  if (algorithm == null) {
    String msg=String.format("String_Node_Str",appId);
    log.error(msg);
    throw new RuntimeException(msg);
  }
  List<String> nextNetworkPartitions=algorithm.getNextNetworkPartitions(algorithmContext);
  if (nextNetworkPartitions == null || nextNetworkPartitions.isEmpty()) {
    String msg=String.format("String_Node_Str",appId);
    log.warn(msg);
    return false;
  }
  for (  String networkPartitionIds : nextNetworkPartitions) {
    ApplicationLevelNetworkPartitionContext context=new ApplicationLevelNetworkPartitionContext(networkPartitionIds);
    ApplicationInstance appInstance=(ApplicationInstance)application.getInstanceByNetworkPartitionId(context.getId());
    if (appInstance != null) {
      instanceId=handleApplicationInstanceCreation(application,context,appInstance);
      initialStartup=false;
    }
 else {
      instanceId=handleApplicationInstanceCreation(application,context,null);
    }
    instanceIds.add(instanceId);
    log.info("String_Node_Str" + networkPartitionIds + "String_Node_Str"+ instanceId);
  }
  startDependency(application,instanceIds);
  return initialStartup;
}

Fixed version (ground truth):
/** 
 * Utility to create application instance by parsing the deployment policy for a monitor
 * @param application the application
 * @return whether the instance created or not
 * @throws TopologyInConsistentException
 * @throws PolicyValidationException
 */
private boolean createInstanceAndStartDependency(Application application) throws TopologyInConsistentException, PolicyValidationException {
  boolean initialStartup=true;
  List<String> instanceIds=new ArrayList<String>();
  String instanceId;
  ApplicationPolicy applicationPolicy=PolicyManager.getInstance().getApplicationPolicy(application.getApplicationPolicyId());
  if (applicationPolicy == null) {
    String msg=String.format("String_Node_Str" + "String_Node_Str",appId);
    log.error(msg);
    throw new RuntimeException(msg);
  }
  NetworkPartitionAlgorithmContext algorithmContext=AutoscalerContext.getInstance().getNetworkPartitionAlgorithmContext(appId);
  if (algorithmContext == null) {
    String msg=String.format("String_Node_Str" + "String_Node_Str",appId);
    log.error(msg);
    throw new RuntimeException(msg);
  }
  String networkPartitionAlgorithmName=applicationPolicy.getAlgorithm();
  if (log.isDebugEnabled()) {
    String msg=String.format("String_Node_Str",networkPartitionAlgorithmName,appId);
    log.debug(msg);
  }
  NetworkPartitionAlgorithm algorithm=getNetworkPartitionAlgorithm(networkPartitionAlgorithmName);
  if (algorithm == null) {
    String msg=String.format("String_Node_Str" + "String_Node_Str",appId);
    log.error(msg);
    throw new RuntimeException(msg);
  }
  List<String> nextNetworkPartitions=algorithm.getNextNetworkPartitions(algorithmContext);
  if (nextNetworkPartitions == null || nextNetworkPartitions.isEmpty()) {
    String msg=String.format("String_Node_Str" + "String_Node_Str",appId);
    log.warn(msg);
    return false;
  }
  for (  String networkPartitionIds : nextNetworkPartitions) {
    ApplicationLevelNetworkPartitionContext context=new ApplicationLevelNetworkPartitionContext(networkPartitionIds);
    ApplicationInstance appInstance=(ApplicationInstance)application.getInstanceByNetworkPartitionId(context.getId());
    if (appInstance != null) {
      instanceId=handleApplicationInstanceCreation(application,context,appInstance);
      initialStartup=false;
    }
 else {
      instanceId=handleApplicationInstanceCreation(application,context,null);
    }
    instanceIds.add(instanceId);
    log.info("String_Node_Str" + networkPartitionIds + "String_Node_Str"+ instanceId);
  }
  startDependency(application,instanceIds);
  return initialStartup;
}