Program: 116049
Project: 116049
Buggy source:
public static void handleApplicationUndeployed(String appId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId);
  }
  Set<ClusterDataHolder> appClusterDataToSend;
  Application application;
  ApplicationHolder.acquireWriteLock();
  try {
    Applications applications=ApplicationHolder.getApplications();
    application=applications.getApplication(appId);
    if (application == null) {
      log.warn(String.format("String_Node_Str",appId));
      return;
    }
 else {
      org.apache.stratos.autoscaler.pojo.policy.deployment.DeploymentPolicy policy=PolicyManager.getInstance().getDeploymentPolicyByApplication(appId);
      if (policy != null) {
        log.warn(String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",appId));
        return;
      }
    }
    appClusterDataToSend=new HashSet<ClusterDataHolder>();
    Set<ClusterDataHolder> appClusterData=application.getClusterDataRecursively();
    for (    ClusterDataHolder currClusterData : appClusterData) {
      ClusterDataHolder newClusterData=new ClusterDataHolder(currClusterData.getServiceType(),currClusterData.getClusterId());
      appClusterDataToSend.add(newClusterData);
    }
    ApplicationHolder.removeApplication(appId);
  }
  finally {
    ApplicationHolder.releaseWriteLock();
  }
  ApplicationsEventPublisher.sendApplicationDeletedEvent(appId,appClusterDataToSend);
}

Fixed version (ground truth):
public static boolean handleApplicationUndeployed(String appId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId);
  }
  Set<ClusterDataHolder> clusterData;
  ApplicationHolder.acquireWriteLock();
  try {
    Applications applications=ApplicationHolder.getApplications();
    Application application=applications.getApplication(appId);
    if (application == null) {
      log.warn(String.format("String_Node_Str",appId));
      return false;
    }
    clusterData=application.getClusterDataRecursively();
    Collection<ApplicationInstance> context=application.getInstanceIdToInstanceContextMap().values();
    ApplicationStatus status=ApplicationStatus.Terminating;
    for (    ApplicationInstance context1 : context) {
      if (context1.isStateTransitionValid(status)) {
        application.setStatus(status,context1.getInstanceId());
        updateApplicationMonitor(appId,status,context1.getInstanceId());
        ApplicationHolder.persistApplication(application);
        ApplicationsEventPublisher.sendApplicationInstanceTerminatingEvent(appId,context1.getInstanceId());
      }
 else {
        log.warn(String.format("String_Node_Str" + "String_Node_Str",appId,context1.getInstanceId() + context1.getStatus(),status));
      }
    }
  }
  finally {
    ApplicationHolder.releaseWriteLock();
  }
  for (  ClusterDataHolder aClusterData : clusterData) {
    if (AutoscalerContext.getInstance().getClusterMonitor(aClusterData.getClusterId()) == null) {
      TopologyManager.acquireReadLockForCluster(aClusterData.getServiceType(),aClusterData.getClusterId());
      try {
        Service service=TopologyManager.getTopology().getService(aClusterData.getServiceType());
        if (service != null) {
          Cluster cluster=service.getCluster(aClusterData.getClusterId());
          if (cluster != null) {
            for (            ClusterInstance instance : cluster.getInstanceIdToInstanceContextMap().values()) {
              ClusterStatusEventPublisher.sendClusterTerminatingEvent(appId,aClusterData.getServiceType(),aClusterData.getClusterId(),instance.getInstanceId());
            }
          }
        }
      }
  finally {
        TopologyManager.releaseReadLockForCluster(aClusterData.getServiceType(),aClusterData.getClusterId());
      }
    }
  }
  return true;
}