Program: 115557
Project: 115557
Buggy source:
public static void handleMemberActivated(InstanceActivatedEvent instanceActivatedEvent){
  Topology topology=TopologyManager.getTopology();
  Service service=topology.getService(instanceActivatedEvent.getServiceName());
  if (service == null) {
    log.warn(String.format("String_Node_Str",instanceActivatedEvent.getServiceName()));
    return;
  }
  Cluster cluster=service.getCluster(instanceActivatedEvent.getClusterId());
  if (cluster == null) {
    log.warn(String.format("String_Node_Str",instanceActivatedEvent.getClusterId()));
    return;
  }
  Member member=cluster.getMember(instanceActivatedEvent.getMemberId());
  if (member == null) {
    log.warn(String.format("String_Node_Str",instanceActivatedEvent.getMemberId()));
    return;
  }
  MemberActivatedEvent memberActivatedEvent=new MemberActivatedEvent(instanceActivatedEvent.getServiceName(),instanceActivatedEvent.getClusterId(),instanceActivatedEvent.getClusterInstanceId(),instanceActivatedEvent.getMemberId(),instanceActivatedEvent.getNetworkPartitionId(),instanceActivatedEvent.getPartitionId());
  memberActivatedEvent.setApplicationId(null);
  try {
    TopologyManager.acquireWriteLock();
    if (!member.isStateTransitionValid(MemberStatus.Active)) {
      log.error("String_Node_Str" + member.getStatus() + "String_Node_Str"+ MemberStatus.Active+ "String_Node_Str");
      return;
    }
 else {
      member.setStatus(MemberStatus.Active);
      try {
        Cartridge cartridge=CloudControllerContext.getInstance().getCartridge(service.getServiceName());
        if (cartridge == null) {
          throw new RuntimeException(String.format("String_Node_Str",service.getServiceName()));
        }
        Port port;
        int portValue;
        List<PortMapping> portMappings=Arrays.asList(cartridge.getPortMappings());
        String clusterId=cluster.getClusterId();
        ClusterContext clusterContext=CloudControllerContext.getInstance().getClusterContext(clusterId);
        List<KubernetesService> kubernetesServices=clusterContext.getKubernetesServices();
        for (        PortMapping portMapping : portMappings) {
          if (kubernetesServices != null) {
            portValue=findKubernetesServicePort(clusterId,kubernetesServices,portMapping);
          }
 else {
            portValue=portMapping.getPort();
          }
          port=new Port(portMapping.getProtocol(),portValue,portMapping.getProxyPort());
          member.addPort(port);
          memberActivatedEvent.addPort(port);
        }
      }
 catch (      Exception e) {
        String message=String.format("String_Node_Str",memberActivatedEvent.getServiceName(),memberActivatedEvent.getMemberId());
        log.error(message,e);
      }
      memberActivatedEvent.setDefaultPrivateIP(member.getDefaultPrivateIP());
      memberActivatedEvent.setMemberPrivateIPs(member.getMemberPrivateIPs());
      memberActivatedEvent.setDefaultPublicIP(member.getDefaultPublicIP());
      memberActivatedEvent.setMemberPublicIPs(member.getMemberPublicIPs());
      TopologyManager.updateTopology(topology);
      TopologyEventPublisher.sendMemberActivatedEvent(memberActivatedEvent);
      BAMUsageDataPublisher.publish(memberActivatedEvent.getMemberId(),memberActivatedEvent.getPartitionId(),memberActivatedEvent.getNetworkPartitionId(),memberActivatedEvent.getClusterId(),memberActivatedEvent.getServiceName(),MemberStatus.Active.toString(),null);
    }
  }
  finally {
    TopologyManager.releaseWriteLock();
  }
}

Fixed version (ground truth):
public static void handleMemberActivated(InstanceActivatedEvent instanceActivatedEvent){
  Topology topology=TopologyManager.getTopology();
  Service service=topology.getService(instanceActivatedEvent.getServiceName());
  if (service == null) {
    log.warn(String.format("String_Node_Str",instanceActivatedEvent.getServiceName()));
    return;
  }
  Cluster cluster=service.getCluster(instanceActivatedEvent.getClusterId());
  if (cluster == null) {
    log.warn(String.format("String_Node_Str",instanceActivatedEvent.getClusterId()));
    return;
  }
  Member member=cluster.getMember(instanceActivatedEvent.getMemberId());
  if (member == null) {
    log.warn(String.format("String_Node_Str",instanceActivatedEvent.getMemberId()));
    return;
  }
  MemberActivatedEvent memberActivatedEvent=new MemberActivatedEvent(instanceActivatedEvent.getServiceName(),instanceActivatedEvent.getClusterId(),instanceActivatedEvent.getClusterInstanceId(),instanceActivatedEvent.getMemberId(),instanceActivatedEvent.getNetworkPartitionId(),instanceActivatedEvent.getPartitionId());
  memberActivatedEvent.setApplicationId(null);
  try {
    TopologyManager.acquireWriteLock();
    if (!member.isStateTransitionValid(MemberStatus.Active)) {
      log.error("String_Node_Str" + member.getStatus() + "String_Node_Str"+ MemberStatus.Active+ "String_Node_Str");
      return;
    }
 else {
      member.setStatus(MemberStatus.Active);
      try {
        Cartridge cartridge=CloudControllerContext.getInstance().getCartridge(service.getServiceUuid());
        if (cartridge == null) {
          throw new RuntimeException(String.format("String_Node_Str",service.getServiceName()));
        }
        Port port;
        int portValue;
        List<PortMapping> portMappings=Arrays.asList(cartridge.getPortMappings());
        String clusterId=cluster.getClusterId();
        ClusterContext clusterContext=CloudControllerContext.getInstance().getClusterContext(clusterId);
        List<KubernetesService> kubernetesServices=clusterContext.getKubernetesServices();
        for (        PortMapping portMapping : portMappings) {
          if (kubernetesServices != null) {
            portValue=findKubernetesServicePort(clusterId,kubernetesServices,portMapping);
          }
 else {
            portValue=portMapping.getPort();
          }
          port=new Port(portMapping.getProtocol(),portValue,portMapping.getProxyPort());
          member.addPort(port);
          memberActivatedEvent.addPort(port);
        }
      }
 catch (      Exception e) {
        String message=String.format("String_Node_Str",memberActivatedEvent.getServiceName(),memberActivatedEvent.getMemberId());
        log.error(message,e);
      }
      memberActivatedEvent.setDefaultPrivateIP(member.getDefaultPrivateIP());
      memberActivatedEvent.setMemberPrivateIPs(member.getMemberPrivateIPs());
      memberActivatedEvent.setDefaultPublicIP(member.getDefaultPublicIP());
      memberActivatedEvent.setMemberPublicIPs(member.getMemberPublicIPs());
      TopologyManager.updateTopology(topology);
      TopologyEventPublisher.sendMemberActivatedEvent(memberActivatedEvent);
      BAMUsageDataPublisher.publish(memberActivatedEvent.getMemberId(),memberActivatedEvent.getPartitionId(),memberActivatedEvent.getNetworkPartitionId(),memberActivatedEvent.getClusterId(),memberActivatedEvent.getServiceName(),MemberStatus.Active.toString(),null);
    }
  }
  finally {
    TopologyManager.releaseWriteLock();
  }
}