Program: 115469
Project: 115469
Buggy source:
public boolean write(Topology topology){
  StringBuilder configurationBuilder=new StringBuilder();
  List<String> availableProtocols=new ArrayList<>();
  for (  Service service : topology.getServices()) {
    for (    Cluster cluster : service.getClusters()) {
      if ((service.getPorts() == null) || (service.getPorts().size() == 0)) {
        throw new RuntimeException(String.format("String_Node_Str",service.getServiceName()));
      }
      for (      Port port : service.getPorts()) {
        if (!availableProtocols.contains(port.getProtocol())) {
          availableProtocols.add(port.getProtocol());
        }
      }
    }
  }
  for (  String protocol1 : availableProtocols) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + protocol1 + "String_Node_Str");
    }
  }
  for (  String protocol : availableProtocols) {
    configurationBuilder.append("String_Node_Str").append("String_Node_Str").append(NEW_LINE);
    configurationBuilder.append(TAB).append("String_Node_Str").append(System.getProperty("String_Node_Str")).append("String_Node_Str").append(NEW_LINE);
    for (    Service service : topology.getServices()) {
      for (      Cluster cluster : service.getClusters()) {
        if ((service.getPorts() == null) || (service.getPorts().size() == 0)) {
          throw new RuntimeException(String.format("String_Node_Str",service.getServiceName()));
        }
        Port selectedPort=null;
        for (        Port port : service.getPorts()) {
          if (port.getProtocol().equals(protocol)) {
            selectedPort=port;
          }
        }
        if (selectedPort != null) {
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + cluster.getClusterId() + "String_Node_Str"+ selectedPort.getValue()+ "String_Node_Str"+ selectedPort.getProtocol()+ "String_Node_Str"+ selectedPort.getProxy());
          }
          generateConfigurationForCluster(cluster,selectedPort,configurationBuilder);
        }
      }
    }
    configurationBuilder.append("String_Node_Str").append(NEW_LINE);
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + configurationBuilder.toString());
    }
  }
  VelocityEngine ve=new VelocityEngine();
  ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,templatePath);
  ve.init();
  Template t=ve.getTemplate(templateName);
  VelocityContext context=new VelocityContext();
  context.put("String_Node_Str",configurationBuilder.toString());
  StringWriter stringWriter=new StringWriter();
  t.merge(context,stringWriter);
  String configuration=stringWriter.toString();
  try {
    BufferedWriter writer=new BufferedWriter(new FileWriter(confFilePath));
    writer.write(configuration);
    writer.close();
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str",confFilePath));
    }
    return true;
  }
 catch (  IOException e) {
    if (log.isErrorEnabled()) {
      log.error(String.format("String_Node_Str",confFilePath));
    }
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
public boolean write(Topology topology){
  StringBuilder configurationBuilder=new StringBuilder();
  List<Port> availablePorts=new ArrayList<Port>();
  for (  Service service : topology.getServices()) {
    for (    Cluster cluster : service.getClusters()) {
      if ((service.getPorts() == null) || (service.getPorts().size() == 0)) {
        throw new RuntimeException(String.format("String_Node_Str",service.getServiceName()));
      }
      for (      Port port : service.getPorts()) {
        for (        Port availablePort : availablePorts) {
          if ((!availablePort.getProtocol().equals(port.getProtocol())) || (availablePort.getProtocol().equals(port.getProtocol()) && availablePort.getProxy() != port.getProxy())) {
            availablePorts.add(port);
          }
        }
      }
    }
  }
  for (  Port port1 : availablePorts) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + port1.getProtocol() + "String_Node_Str"+ port1.getProxy()+ "String_Node_Str");
    }
  }
  for (  Port availPort : availablePorts) {
    configurationBuilder.append("String_Node_Str").append("String_Node_Str").append(NEW_LINE);
    configurationBuilder.append(TAB).append("String_Node_Str").append(System.getProperty("String_Node_Str")).append("String_Node_Str").append(NEW_LINE);
    for (    Service service : topology.getServices()) {
      for (      Cluster cluster : service.getClusters()) {
        if ((service.getPorts() == null) || (service.getPorts().size() == 0)) {
          throw new RuntimeException(String.format("String_Node_Str",service.getServiceName()));
        }
        Port selectedPort=null;
        for (        Port port : service.getPorts()) {
          if ((port.getProtocol().equals(availPort.getProtocol())) && (port.getProxy() == availPort.getProxy())) {
            selectedPort=port;
          }
        }
        if (selectedPort != null) {
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + cluster.getClusterId() + "String_Node_Str"+ selectedPort.getValue()+ "String_Node_Str"+ selectedPort.getProtocol()+ "String_Node_Str"+ selectedPort.getProxy());
          }
          generateConfigurationForCluster(cluster,selectedPort,configurationBuilder);
        }
      }
    }
    configurationBuilder.append("String_Node_Str").append(NEW_LINE);
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + configurationBuilder.toString());
    }
  }
  VelocityEngine ve=new VelocityEngine();
  ve.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,templatePath);
  ve.init();
  Template t=ve.getTemplate(templateName);
  VelocityContext context=new VelocityContext();
  context.put("String_Node_Str",configurationBuilder.toString());
  StringWriter stringWriter=new StringWriter();
  t.merge(context,stringWriter);
  String configuration=stringWriter.toString();
  try {
    BufferedWriter writer=new BufferedWriter(new FileWriter(confFilePath));
    writer.write(configuration);
    writer.close();
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str",confFilePath));
    }
    return true;
  }
 catch (  IOException e) {
    if (log.isErrorEnabled()) {
      log.error(String.format("String_Node_Str",confFilePath));
    }
    throw new RuntimeException(e);
  }
}