Program: 105448
Project: 105448
Buggy source:
protected LibvirtVMDef createVMFromSpec(VirtualMachineTO vmTO){
  LibvirtVMDef vm=new LibvirtVMDef();
  vm.setDomainName(vmTO.getName());
  String uuid=vmTO.getUuid();
  uuid=getUuid(uuid);
  vm.setDomUUID(uuid);
  vm.setDomDescription(vmTO.getOs());
  vm.setPlatformEmulator(vmTO.getPlatformEmulator());
  GuestDef guest=new GuestDef();
  if (HypervisorType.LXC == _hypervisorType && VirtualMachine.Type.User == vmTO.getType()) {
    guest.setGuestType(GuestDef.guestType.LXC);
    vm.setHvsType(HypervisorType.LXC.toString().toLowerCase());
  }
 else {
    guest.setGuestType(GuestDef.guestType.KVM);
    vm.setHvsType(HypervisorType.KVM.toString().toLowerCase());
    vm.setLibvirtVersion(_hypervisorLibvirtVersion);
    vm.setQemuVersion(_hypervisorQemuVersion);
  }
  guest.setGuestArch(vmTO.getArch());
  guest.setMachineType("String_Node_Str");
  guest.setBootOrder(GuestDef.bootOrder.CDROM);
  guest.setBootOrder(GuestDef.bootOrder.HARDISK);
  vm.addComp(guest);
  GuestResourceDef grd=new GuestResourceDef();
  if (vmTO.getMinRam() != vmTO.getMaxRam() && !_noMemBalloon) {
    grd.setMemBalloning(true);
    grd.setCurrentMem(vmTO.getMinRam() / 1024);
    grd.setMemorySize(vmTO.getMaxRam() / 1024);
  }
 else {
    grd.setMemorySize(vmTO.getMaxRam() / 1024);
  }
  int vcpus=vmTO.getCpus();
  grd.setVcpuNum(vcpus);
  vm.addComp(grd);
  CpuModeDef cmd=new CpuModeDef();
  cmd.setMode(_guestCpuMode);
  cmd.setModel(_guestCpuModel);
  if (vcpus % 6 == 0) {
    int sockets=vcpus / 6;
    cmd.setTopology(6,sockets);
  }
 else   if (vcpus % 4 == 0) {
    int sockets=vcpus / 4;
    cmd.setTopology(4,sockets);
  }
  vm.addComp(cmd);
  if (_hypervisorLibvirtVersion >= 9000) {
    CpuTuneDef ctd=new CpuTuneDef();
    if (vmTO.getMinSpeed() != null) {
      ctd.setShares(vmTO.getCpus() * vmTO.getMinSpeed());
    }
 else {
      ctd.setShares(vmTO.getCpus() * vmTO.getSpeed());
    }
    vm.addComp(ctd);
  }
  FeaturesDef features=new FeaturesDef();
  features.addFeatures("String_Node_Str");
  features.addFeatures("String_Node_Str");
  features.addFeatures("String_Node_Str");
  vm.addComp(features);
  TermPolicy term=new TermPolicy();
  term.setCrashPolicy("String_Node_Str");
  term.setPowerOffPolicy("String_Node_Str");
  term.setRebootPolicy("String_Node_Str");
  vm.addComp(term);
  ClockDef clock=new ClockDef();
  if (vmTO.getOs().startsWith("String_Node_Str")) {
    clock.setClockOffset(ClockDef.ClockOffset.LOCALTIME);
    clock.setTimer("String_Node_Str","String_Node_Str",null);
  }
 else   if (vmTO.getType() != VirtualMachine.Type.User || isGuestPVEnabled(vmTO.getOs())) {
    clock.setTimer("String_Node_Str","String_Node_Str",null,_noKvmClock);
  }
  vm.addComp(clock);
  DevicesDef devices=new DevicesDef();
  devices.setEmulatorPath(_hypervisorPath);
  devices.setGuestType(guest.getGuestType());
  SerialDef serial=new SerialDef("String_Node_Str",null,(short)0);
  devices.addDevice(serial);
  if (vmTO.getType() != VirtualMachine.Type.User) {
    VirtioSerialDef vserial=new VirtioSerialDef(vmTO.getName(),null);
    devices.addDevice(vserial);
  }
  VideoDef videoCard=new VideoDef(_videoHw,_videoRam);
  devices.addDevice(videoCard);
  ConsoleDef console=new ConsoleDef("String_Node_Str",null,null,(short)0);
  devices.addDevice(console);
  String passwd=vmTO.getVncPassword();
  GraphicDef grap=new GraphicDef("String_Node_Str",(short)0,true,vmTO.getVncAddr(),passwd,null);
  devices.addDevice(grap);
  InputDef input=new InputDef("String_Node_Str","String_Node_Str");
  devices.addDevice(input);
  vm.addComp(devices);
  return vm;
}

Fixed version (ground truth):
protected LibvirtVMDef createVMFromSpec(VirtualMachineTO vmTO){
  LibvirtVMDef vm=new LibvirtVMDef();
  vm.setDomainName(vmTO.getName());
  String uuid=vmTO.getUuid();
  uuid=getUuid(uuid);
  vm.setDomUUID(uuid);
  vm.setDomDescription(vmTO.getOs());
  vm.setPlatformEmulator(vmTO.getPlatformEmulator());
  GuestDef guest=new GuestDef();
  if (HypervisorType.LXC == _hypervisorType && VirtualMachine.Type.User == vmTO.getType()) {
    guest.setGuestType(GuestDef.guestType.LXC);
    vm.setHvsType(HypervisorType.LXC.toString().toLowerCase());
  }
 else {
    guest.setGuestType(GuestDef.guestType.KVM);
    vm.setHvsType(HypervisorType.KVM.toString().toLowerCase());
    vm.setLibvirtVersion(_hypervisorLibvirtVersion);
    vm.setQemuVersion(_hypervisorQemuVersion);
  }
  guest.setGuestArch(vmTO.getArch());
  guest.setMachineType("String_Node_Str");
  guest.setBootOrder(GuestDef.bootOrder.CDROM);
  guest.setBootOrder(GuestDef.bootOrder.HARDISK);
  vm.addComp(guest);
  GuestResourceDef grd=new GuestResourceDef();
  if (vmTO.getMinRam() != vmTO.getMaxRam() && !_noMemBalloon) {
    grd.setMemBalloning(true);
    grd.setCurrentMem(vmTO.getMinRam() / 1024);
    grd.setMemorySize(vmTO.getMaxRam() / 1024);
  }
 else {
    grd.setMemorySize(vmTO.getMaxRam() / 1024);
  }
  int vcpus=vmTO.getCpus();
  grd.setVcpuNum(vcpus);
  vm.addComp(grd);
  CpuModeDef cmd=new CpuModeDef();
  cmd.setMode(_guestCpuMode);
  cmd.setModel(_guestCpuModel);
  if (vcpus % 6 == 0) {
    int sockets=vcpus / 6;
    cmd.setTopology(6,sockets);
  }
 else   if (vcpus % 4 == 0) {
    int sockets=vcpus / 4;
    cmd.setTopology(4,sockets);
  }
  vm.addComp(cmd);
  if (_hypervisorLibvirtVersion >= 9000) {
    CpuTuneDef ctd=new CpuTuneDef();
    if (vmTO.getMinSpeed() != null) {
      ctd.setShares(vmTO.getCpus() * vmTO.getMinSpeed());
    }
 else {
      ctd.setShares(vmTO.getCpus() * vmTO.getSpeed());
    }
    vm.addComp(ctd);
  }
  FeaturesDef features=new FeaturesDef();
  features.addFeatures("String_Node_Str");
  features.addFeatures("String_Node_Str");
  features.addFeatures("String_Node_Str");
  if (vmTO.getOs().contains("String_Node_Str") && hostOsVersion != null && ((hostOsVersion.first() == 6 && hostOsVersion.second() >= 5) || (hostOsVersion.first() >= 7))) {
    LibvirtVMDef.HyperVEnlightenmentFeatureDef hyv=new LibvirtVMDef.HyperVEnlightenmentFeatureDef();
    hyv.setRelaxed(true);
    features.addHyperVFeature(hyv);
  }
  vm.addComp(features);
  TermPolicy term=new TermPolicy();
  term.setCrashPolicy("String_Node_Str");
  term.setPowerOffPolicy("String_Node_Str");
  term.setRebootPolicy("String_Node_Str");
  vm.addComp(term);
  ClockDef clock=new ClockDef();
  if (vmTO.getOs().startsWith("String_Node_Str")) {
    clock.setClockOffset(ClockDef.ClockOffset.LOCALTIME);
    clock.setTimer("String_Node_Str","String_Node_Str",null);
  }
 else   if (vmTO.getType() != VirtualMachine.Type.User || isGuestPVEnabled(vmTO.getOs())) {
    clock.setTimer("String_Node_Str","String_Node_Str",null,_noKvmClock);
  }
  vm.addComp(clock);
  DevicesDef devices=new DevicesDef();
  devices.setEmulatorPath(_hypervisorPath);
  devices.setGuestType(guest.getGuestType());
  SerialDef serial=new SerialDef("String_Node_Str",null,(short)0);
  devices.addDevice(serial);
  if (vmTO.getType() != VirtualMachine.Type.User) {
    VirtioSerialDef vserial=new VirtioSerialDef(vmTO.getName(),null);
    devices.addDevice(vserial);
  }
  VideoDef videoCard=new VideoDef(_videoHw,_videoRam);
  devices.addDevice(videoCard);
  ConsoleDef console=new ConsoleDef("String_Node_Str",null,null,(short)0);
  devices.addDevice(console);
  String passwd=vmTO.getVncPassword();
  GraphicDef grap=new GraphicDef("String_Node_Str",(short)0,true,vmTO.getVncAddr(),passwd,null);
  devices.addDevice(grap);
  InputDef input=new InputDef("String_Node_Str","String_Node_Str");
  devices.addDevice(input);
  vm.addComp(devices);
  return vm;
}