Program: 115990
Project: 115990
Buggy source:
/** 
 * Create proxy services for the cluster and add them to the cluster context.
 * @param clusterContext
 * @param kubernetesClusterContext
 * @param kubernetesApi
 * @return
 * @throws KubernetesClientException
 */
private List<Service> createProxyServices(ClusterContext clusterContext,KubernetesClusterContext kubernetesClusterContext,KubernetesApiClient kubernetesApi) throws KubernetesClientException {
  List<Service> services=new ArrayList<Service>();
  String clusterId=clusterContext.getClusterId();
  Cartridge cartridge=CloudControllerContext.getInstance().getCartridge(clusterContext.getCartridgeType());
  if (cartridge == null) {
    String message="String_Node_Str" + clusterContext.getCartridgeType();
    log.error(message);
    throw new RuntimeException(message);
  }
  List<PortMapping> portMappings=cartridge.getPortMappings();
  for (  PortMapping portMapping : portMappings) {
    String serviceId=KubernetesIaasUtil.prepareKubernetesServiceId(CloudControllerUtil.replaceDotsWithDash(clusterId),portMapping);
    int nextServicePort=kubernetesClusterContext.getNextServicePort();
    if (nextServicePort == -1) {
      throw new RuntimeException(String.format("String_Node_Str",clusterContext.getClusterId()));
    }
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str" + "String_Node_Str",clusterId,serviceId,portMapping.getProtocol(),nextServicePort,portMapping.getPort(),portMapping.getProxyPort()));
    }
    String serviceName=serviceId;
    int servicePort=nextServicePort;
    int containerPort=Integer.parseInt(portMapping.getPort());
    String publicIp=kubernetesClusterContext.getMasterIp();
    kubernetesApi.createService(serviceId,serviceName,servicePort,containerPort,publicIp);
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException ignore) {
    }
    Service service=kubernetesApi.getService(serviceId);
    services.add(service);
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str" + "String_Node_Str",clusterId,service.getId(),portMapping.getProtocol(),service.getPort(),portMapping.getPort(),portMapping.getProxyPort()));
    }
  }
  return services;
}

Fixed version (ground truth):
/** 
 * Create proxy services for the cluster and add them to the cluster context.
 * @param clusterContext
 * @param kubernetesClusterContext
 * @param kubernetesApi
 * @return
 * @throws KubernetesClientException
 */
private List<Service> createProxyServices(ClusterContext clusterContext,KubernetesClusterContext kubernetesClusterContext,KubernetesApiClient kubernetesApi) throws KubernetesClientException {
  List<Service> services=new ArrayList<Service>();
  String clusterId=clusterContext.getClusterId();
  Cartridge cartridge=CloudControllerContext.getInstance().getCartridge(clusterContext.getCartridgeType());
  if (cartridge == null) {
    String message="String_Node_Str" + clusterContext.getCartridgeType();
    log.error(message);
    throw new RuntimeException(message);
  }
  boolean kubernetesServicePortsAdded=false;
  for (  PortMapping portMapping : cartridge.getPortMappings()) {
    String serviceId=KubernetesIaasUtil.generateKubernetesServiceId(CloudControllerUtil.replaceDotsWithDash(clusterId),portMapping);
    int nextServicePort=kubernetesClusterContext.getNextServicePort();
    if (nextServicePort == -1) {
      throw new RuntimeException(String.format("String_Node_Str",clusterContext.getClusterId()));
    }
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str" + "String_Node_Str",clusterId,serviceId,portMapping.getProtocol(),nextServicePort,portMapping.getPort()));
    }
    String serviceName=clusterId;
    int servicePort=nextServicePort;
    String containerPortName=KubernetesIaasUtil.generatePortName(portMapping);
    String publicIp=kubernetesClusterContext.getMasterIp();
    kubernetesApi.createService(serviceId,serviceName,servicePort,containerPortName,publicIp);
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException ignore) {
    }
    Service service=kubernetesApi.getService(serviceId);
    services.add(service);
    portMapping.setKubernetesServicePort(nextServicePort);
    kubernetesServicePortsAdded=true;
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str" + "String_Node_Str",clusterId,serviceId,portMapping.getProtocol(),nextServicePort,portMapping.getPort()));
    }
  }
  if (kubernetesServicePortsAdded) {
    CloudControllerContext.getInstance().persist();
  }
  return services;
}