Program: 41009
Project: 41009
Buggy source:
private void rewriteServiceNames(Deploy deploy,List<File> referencedFiles,String csarName) throws WSDLException, FileNotFoundException {
  WSDLFactory factory=WSDLFactory.newInstance();
  WSDLReader reader=factory.newWSDLReader();
  WSDLWriter writer=factory.newWSDLWriter();
  List<TInvoke> invokes=deploy.getProcess().get(0).getInvoke();
  List<TProvide> provides=deploy.getProcess().get(0).getProvide();
  List<QName> servicesToRewrite=new ArrayList<QName>();
  for (  TInvoke invoke : invokes) {
    if (invoke.getPartnerLink().equals("String_Node_Str")) {
      continue;
    }
    TService service=invoke.getService();
    QName serviceName=service.getName();
    servicesToRewrite.add(serviceName);
    QName renamedServiceName=new QName(serviceName.getNamespaceURI(),csarName + serviceName.getLocalPart());
    service.setName(renamedServiceName);
    invoke.setService(service);
  }
  for (  TProvide provide : provides) {
    if (provide.getPartnerLink().equals("String_Node_Str")) {
      continue;
    }
    TService service=provide.getService();
    QName serviceName=service.getName();
    servicesToRewrite.add(serviceName);
    QName renamedServiceName=new QName(serviceName.getNamespaceURI(),csarName + serviceName.getLocalPart());
    service.setName(renamedServiceName);
    provide.setService(service);
  }
  for (  QName serviceName : servicesToRewrite) {
    for (    File file : referencedFiles) {
      if (!file.getAbsolutePath().endsWith("String_Node_Str")) {
        continue;
      }
      Definition def=reader.readWSDL(file.getAbsolutePath());
      List<QName> servicesToRemove=new ArrayList<QName>();
      for (      Object obj : def.getAllServices().values()) {
        Service service=(Service)obj;
        if (serviceName.toString().equals(service.getQName().toString())) {
          servicesToRemove.add(service.getQName());
          Service newService=new ServiceImpl();
          for (          Object o : service.getPorts().values()) {
            Port port=(Port)o;
            newService.addPort(port);
          }
          newService.setQName(new QName(serviceName.getNamespaceURI(),csarName + serviceName.getLocalPart()));
          def.addService(newService);
        }
      }
      for (      QName serviceToRemove : servicesToRemove) {
        def.removeService(serviceToRemove);
      }
      writer.writeWSDL(def,new FileOutputStream(file));
    }
  }
}

Fixed version (ground truth):
private void rewriteServiceNames(Deploy deploy,List<File> referencedFiles,String csarName) throws WSDLException, FileNotFoundException {
  WSDLFactory factory=WSDLFactory.newInstance();
  WSDLReader reader=factory.newWSDLReader();
  WSDLWriter writer=factory.newWSDLWriter();
  List<TInvoke> invokes=deploy.getProcess().get(0).getInvoke();
  List<TProvide> provides=deploy.getProcess().get(0).getProvide();
  List<QName> servicesToRewrite=new ArrayList<QName>();
  for (  TInvoke invoke : invokes) {
    if (invoke.getPartnerLink().equals("String_Node_Str")) {
      continue;
    }
    TService service=invoke.getService();
    QName serviceName=service.getName();
    servicesToRewrite.add(serviceName);
    QName renamedServiceName=new QName(serviceName.getNamespaceURI(),csarName + serviceName.getLocalPart());
    service.setName(renamedServiceName);
    invoke.setService(service);
  }
  for (  TProvide provide : provides) {
    if (provide.getPartnerLink().equals("String_Node_Str")) {
      continue;
    }
    TService service=provide.getService();
    QName serviceName=service.getName();
    servicesToRewrite.add(serviceName);
    QName renamedServiceName=new QName(serviceName.getNamespaceURI(),csarName + serviceName.getLocalPart());
    service.setName(renamedServiceName);
    provide.setService(service);
  }
  for (  QName serviceName : servicesToRewrite) {
    for (    File file : referencedFiles) {
      if (!file.getAbsolutePath().endsWith("String_Node_Str")) {
        continue;
      }
      Definition def=reader.readWSDL(file.getAbsolutePath());
      List<QName> servicesToRemove=new ArrayList<QName>();
      for (      Object obj : def.getAllServices().values()) {
        Service service=(Service)obj;
        if (serviceName.equals(service.getQName())) {
          servicesToRemove.add(service.getQName());
          Service newService=new ServiceImpl();
          for (          Object o : service.getPorts().values()) {
            Port port=(Port)o;
            newService.addPort(port);
          }
          newService.setQName(new QName(serviceName.getNamespaceURI(),csarName + serviceName.getLocalPart()));
          def.addService(newService);
        }
      }
      for (      QName serviceToRemove : servicesToRemove) {
        def.removeService(serviceToRemove);
      }
      writer.writeWSDL(def,new FileOutputStream(file));
    }
  }
}