Program: 115848
Project: 115848
Buggy source:
@Override public void onParentScalingEvent(ScalingEvent scalingEvent){
  log.info("String_Node_Str" + this.getId() + "String_Node_Str"+ scalingEvent.getNetworkPartitionId()+ "String_Node_Str"+ scalingEvent.getId()+ "String_Node_Str"+ scalingEvent.getInstanceId()+ "String_Node_Str"+ scalingEvent.getFactor());
  String networkPartitionId=scalingEvent.getNetworkPartitionId();
  final String parentInstanceId=scalingEvent.getInstanceId();
  final NetworkPartitionContext networkPartitionContext=this.networkPartitionCtxts.get(networkPartitionId);
  float factor=scalingEvent.getFactor();
  int currentInstances=networkPartitionContext.getNonTerminatedInstancesCount();
  float requiredInstances=factor * ((GroupLevelNetworkPartitionContext)networkPartitionContext).getMinInstanceCount();
  float additionalInstances=requiredInstances - currentInstances;
  if (additionalInstances >= 1) {
    createGroupInstanceOnScaling(networkPartitionContext,parentInstanceId);
  }
 else {
    if (networkPartitionContext.getPendingInstancesCount() != 0) {
      ApplicationBuilder.handleGroupTerminatingEvent(appId,this.id,networkPartitionContext.getPendingInstances().get(0).getId());
    }
 else {
      List<InstanceContext> activeInstances=networkPartitionContext.getActiveInstances();
      ApplicationBuilder.handleGroupTerminatingEvent(appId,this.id,activeInstances.get(activeInstances.size() - 1).toString());
    }
  }
}

Fixed version (ground truth):
@Override public void onParentScalingEvent(ScalingEvent scalingEvent){
  log.info("String_Node_Str" + this.getId() + "String_Node_Str"+ scalingEvent.getNetworkPartitionId()+ "String_Node_Str"+ scalingEvent.getId()+ "String_Node_Str"+ scalingEvent.getInstanceId()+ "String_Node_Str"+ scalingEvent.getFactor());
  String networkPartitionId=scalingEvent.getNetworkPartitionId();
  final String parentInstanceId=scalingEvent.getInstanceId();
  final NetworkPartitionContext networkPartitionContext=this.networkPartitionCtxts.get(networkPartitionId);
  float factor=scalingEvent.getFactor();
  int currentInstances=networkPartitionContext.getNonTerminatedInstancesCount();
  float requiredInstances=factor * ((GroupLevelNetworkPartitionContext)networkPartitionContext).getMinInstanceCount();
  int ceilingRequiredInstances=(int)Math.ceil(requiredInstances);
  if (ceilingRequiredInstances > currentInstances) {
    int instancesToBeCreated=ceilingRequiredInstances - currentInstances;
    for (int count=0; count < instancesToBeCreated; count++) {
      createGroupInstanceOnScaling(networkPartitionContext,parentInstanceId);
    }
  }
 else   if (ceilingRequiredInstances < currentInstances) {
    int instancesToBeTerminated=currentInstances - ceilingRequiredInstances;
    for (int count=0; count < instancesToBeTerminated; count++) {
      if (networkPartitionContext.getPendingInstancesCount() != 0) {
        ApplicationBuilder.handleGroupTerminatingEvent(appId,this.id,networkPartitionContext.getPendingInstances().get(0).getId());
      }
 else {
        List<InstanceContext> activeInstances=networkPartitionContext.getActiveInstances();
        ApplicationBuilder.handleGroupTerminatingEvent(appId,this.id,activeInstances.get(activeInstances.size() - 1).toString());
      }
    }
  }
}