Program: 115461
Project: 115461
Buggy source:
public static void handleClusterActivatedEvent(ClusterStatusClusterActivatedEvent clusterStatusClusterActivatedEvent) throws RegistryException {
  Topology topology=TopologyManager.getTopology();
  Service service=topology.getService(clusterStatusClusterActivatedEvent.getServiceName());
  if (service == null) {
    throw new RuntimeException(String.format("String_Node_Str",clusterStatusClusterActivatedEvent.getServiceName()));
  }
  Cluster cluster=service.getCluster(clusterStatusClusterActivatedEvent.getClusterId());
  if (cluster == null) {
    throw new RuntimeException(String.format("String_Node_Str",clusterStatusClusterActivatedEvent.getClusterId(),clusterStatusClusterActivatedEvent.getServiceName()));
  }
  String applicationId=cluster.getAppId();
  String clusterId=cluster.getClusterId();
  ClusterContext clusterContext=CloudControllerContext.getInstance().getClusterContext(clusterId);
  if (clusterContext == null) {
    throw new RuntimeException(String.format("String_Node_Str",clusterId));
  }
  ClusterInstanceActivatedEvent clusterInstanceActivatedEvent=new ClusterInstanceActivatedEvent(clusterStatusClusterActivatedEvent.getAppId(),clusterStatusClusterActivatedEvent.getServiceName(),clusterStatusClusterActivatedEvent.getClusterId(),clusterStatusClusterActivatedEvent.getInstanceId());
  try {
    TopologyManager.acquireWriteLock();
    Collection<KubernetesService> kubernetesServices=clusterContext.getKubernetesServices(clusterStatusClusterActivatedEvent.getInstanceId());
    if ((kubernetesServices != null) && (kubernetesServices.size() > 0)) {
      try {
        Set<String> nodePublicIps=new HashSet<>();
        for (        KubernetesService kubernetesService : kubernetesServices) {
          nodePublicIps.addAll(Arrays.asList(kubernetesService.getPublicIPs()));
          if (kubernetesService.getServiceType().equals(KubernetesConstants.NODE_PORT)) {
            for (            String hostname : cluster.getHostNames()) {
              int port=kubernetesService.getPort();
              if (cluster.getLoadBalancerIps().size() > 0) {
                port=findProxyPort(applicationId,clusterId,kubernetesService.getPortName());
              }
              URI accessURL=new URI(kubernetesService.getProtocol(),null,hostname,port,null,null,null);
              cluster.addAccessUrl(clusterStatusClusterActivatedEvent.getInstanceId(),accessURL.toString());
              clusterInstanceActivatedEvent.addAccessUrl(accessURL.toString());
            }
          }
        }
        if (cluster.getLoadBalancerIps().size() == 0) {
          List<String> nodePublicIpsList=new ArrayList<>();
          nodePublicIpsList.addAll(nodePublicIps);
          clusterInstanceActivatedEvent.setLoadBalancerIps(nodePublicIpsList);
        }
        log.info(String.format("String_Node_Str" + "String_Node_Str",applicationId,clusterId,clusterInstanceActivatedEvent.getAccessUrls()));
      }
 catch (      URISyntaxException e) {
        log.error("String_Node_Str",e);
      }
    }
 else {
      try {
        List<ClusterPortMapping> portMappings=CloudControllerContext.getInstance().getClusterPortMappings(applicationId,clusterId);
        for (        ClusterPortMapping portMapping : portMappings) {
          for (          String hostname : cluster.getHostNames()) {
            URI accessURL=new URI(portMapping.getProtocol(),null,hostname,portMapping.getPort(),null,null,null);
            cluster.addAccessUrl(clusterStatusClusterActivatedEvent.getInstanceId(),accessURL.toString());
            clusterInstanceActivatedEvent.addAccessUrl(accessURL.toString());
          }
        }
        log.info(String.format("String_Node_Str",applicationId,clusterId,clusterInstanceActivatedEvent.getAccessUrls()));
      }
 catch (      URISyntaxException e) {
        log.error("String_Node_Str",e);
      }
    }
    ClusterInstance context=cluster.getInstanceContexts(clusterStatusClusterActivatedEvent.getInstanceId());
    if (context == null) {
      throw new RuntimeException("String_Node_Str" + clusterStatusClusterActivatedEvent.getClusterId() + "String_Node_Str"+ clusterStatusClusterActivatedEvent.getInstanceId());
    }
    ClusterStatus status=ClusterStatus.Active;
    if (context.isStateTransitionValid(status)) {
      context.setStatus(status);
      log.info("String_Node_Str" + cluster.getClusterId());
      TopologyManager.updateTopology(topology);
      TopologyEventPublisher.sendClusterActivatedEvent(clusterInstanceActivatedEvent);
    }
 else {
      throw new RuntimeException(String.format("String_Node_Str" + "String_Node_Str",clusterStatusClusterActivatedEvent.getClusterId(),clusterStatusClusterActivatedEvent.getInstanceId(),context.getStatus(),status));
    }
  }
  finally {
    TopologyManager.releaseWriteLock();
  }
}

Fixed version (ground truth):
public static void handleClusterActivatedEvent(ClusterStatusClusterActivatedEvent clusterStatusClusterActivatedEvent) throws RegistryException {
  Topology topology=TopologyManager.getTopology();
  Service service=topology.getService(clusterStatusClusterActivatedEvent.getServiceName());
  if (service == null) {
    throw new RuntimeException(String.format("String_Node_Str",clusterStatusClusterActivatedEvent.getServiceName()));
  }
  Cluster cluster=service.getCluster(clusterStatusClusterActivatedEvent.getClusterId());
  if (cluster == null) {
    throw new RuntimeException(String.format("String_Node_Str",clusterStatusClusterActivatedEvent.getClusterId(),clusterStatusClusterActivatedEvent.getServiceName()));
  }
  String applicationId=cluster.getAppId();
  String clusterId=cluster.getClusterId();
  ClusterContext clusterContext=CloudControllerContext.getInstance().getClusterContext(clusterId);
  if (clusterContext == null) {
    throw new RuntimeException(String.format("String_Node_Str",clusterId));
  }
  ClusterInstanceActivatedEvent clusterInstanceActivatedEvent=new ClusterInstanceActivatedEvent(clusterStatusClusterActivatedEvent.getAppId(),clusterStatusClusterActivatedEvent.getServiceName(),clusterStatusClusterActivatedEvent.getClusterId(),clusterStatusClusterActivatedEvent.getInstanceId());
  try {
    TopologyManager.acquireWriteLock();
    Collection<KubernetesService> kubernetesServices=clusterContext.getKubernetesServices(clusterStatusClusterActivatedEvent.getInstanceId());
    if ((kubernetesServices != null) && (kubernetesServices.size() > 0)) {
      try {
        Set<String> nodePublicIps=new HashSet<>();
        for (        KubernetesService kubernetesService : kubernetesServices) {
          nodePublicIps.addAll(Arrays.asList(kubernetesService.getPublicIPs()));
          if (kubernetesService.getServiceType().equals(KubernetesConstants.NODE_PORT)) {
            for (            String hostname : cluster.getHostNames()) {
              int port=kubernetesService.getPort();
              if (cluster.getLoadBalancerIps().size() > 0) {
                port=findProxyPort(applicationId,clusterId,kubernetesService.getPortName());
              }
              URI accessURL=new URI(kubernetesService.getProtocol(),null,hostname,port,null,null,null);
              cluster.addAccessUrl(clusterStatusClusterActivatedEvent.getInstanceId(),accessURL.toString());
              clusterInstanceActivatedEvent.addAccessUrl(accessURL.toString());
            }
          }
        }
        if (cluster.getLoadBalancerIps().size() == 0) {
          List<String> nodePublicIpsList=new ArrayList<>();
          nodePublicIpsList.addAll(nodePublicIps);
          cluster.setLoadBalancerIps(nodePublicIpsList);
          clusterInstanceActivatedEvent.setLoadBalancerIps(nodePublicIpsList);
        }
        log.info(String.format("String_Node_Str" + "String_Node_Str",applicationId,clusterId,clusterInstanceActivatedEvent.getAccessUrls()));
      }
 catch (      URISyntaxException e) {
        log.error("String_Node_Str",e);
      }
    }
 else {
      try {
        List<ClusterPortMapping> portMappings=CloudControllerContext.getInstance().getClusterPortMappings(applicationId,clusterId);
        for (        ClusterPortMapping portMapping : portMappings) {
          for (          String hostname : cluster.getHostNames()) {
            URI accessURL=new URI(portMapping.getProtocol(),null,hostname,portMapping.getPort(),null,null,null);
            cluster.addAccessUrl(clusterStatusClusterActivatedEvent.getInstanceId(),accessURL.toString());
            clusterInstanceActivatedEvent.addAccessUrl(accessURL.toString());
          }
        }
        log.info(String.format("String_Node_Str",applicationId,clusterId,clusterInstanceActivatedEvent.getAccessUrls()));
      }
 catch (      URISyntaxException e) {
        log.error("String_Node_Str",e);
      }
    }
    ClusterInstance context=cluster.getInstanceContexts(clusterStatusClusterActivatedEvent.getInstanceId());
    if (context == null) {
      throw new RuntimeException("String_Node_Str" + clusterStatusClusterActivatedEvent.getClusterId() + "String_Node_Str"+ clusterStatusClusterActivatedEvent.getInstanceId());
    }
    ClusterStatus status=ClusterStatus.Active;
    if (context.isStateTransitionValid(status)) {
      context.setStatus(status);
      log.info("String_Node_Str" + cluster.getClusterId());
      TopologyManager.updateTopology(topology);
      TopologyEventPublisher.sendClusterActivatedEvent(clusterInstanceActivatedEvent);
    }
 else {
      throw new RuntimeException(String.format("String_Node_Str" + "String_Node_Str",clusterStatusClusterActivatedEvent.getClusterId(),clusterStatusClusterActivatedEvent.getInstanceId(),context.getStatus(),status));
    }
  }
  finally {
    TopologyManager.releaseWriteLock();
  }
}