Program: 105125
Project: 105125
Buggy source:
public VM createWorkingVM(final Connection conn,final String vmName,final String guestOSType,final String platformEmulator,final List<VolumeObjectTO> listVolumeTo) throws BadServerResponse, Types.VmBadPowerState, Types.SrFull, Types.OperationNotAllowed, XenAPIException, XmlRpcException {
  final String guestOsTypeName=platformEmulator;
  if (guestOsTypeName == null) {
    final String msg="String_Node_Str" + this.getClass().getName() + "String_Node_Str"+ guestOSType+ "String_Node_Str";
    s_logger.warn(msg);
    throw new CloudRuntimeException(msg);
  }
  final VM template=getVM(conn,guestOsTypeName);
  final VM vm=template.createClone(conn,vmName);
  vm.setIsATemplate(conn,false);
  final Map<VDI,VolumeObjectTO> vdiMap=new HashMap<VDI,VolumeObjectTO>();
  for (  final VolumeObjectTO volume : listVolumeTo) {
    final String vdiUuid=volume.getPath();
    try {
      final VDI vdi=VDI.getByUuid(conn,vdiUuid);
      vdiMap.put(vdi,volume);
    }
 catch (    final Types.UuidInvalid e) {
      s_logger.warn("String_Node_Str" + vdiUuid + "String_Node_Str");
    }
  }
  for (  final Map.Entry<VDI,VolumeObjectTO> entry : vdiMap.entrySet()) {
    final VDI vdi=entry.getKey();
    final VolumeObjectTO volumeTO=entry.getValue();
    final VBD.Record vbdr=new VBD.Record();
    vbdr.VM=vm;
    vbdr.VDI=vdi;
    if (volumeTO.getVolumeType() == Volume.Type.ROOT) {
      vbdr.bootable=true;
      vbdr.unpluggable=false;
    }
 else {
      vbdr.bootable=false;
      vbdr.unpluggable=true;
    }
    vbdr.userdevice="String_Node_Str";
    vbdr.mode=Types.VbdMode.RW;
    vbdr.type=Types.VbdType.DISK;
    VBD.create(conn,vbdr);
  }
  return vm;
}

Fixed version (ground truth):
public VM createWorkingVM(final Connection conn,final String vmName,final String guestOSType,final String platformEmulator,final List<VolumeObjectTO> listVolumeTo) throws BadServerResponse, Types.VmBadPowerState, Types.SrFull, Types.OperationNotAllowed, XenAPIException, XmlRpcException {
  final String guestOsTypeName=platformEmulator;
  if (guestOsTypeName == null) {
    final String msg="String_Node_Str" + this.getClass().getName() + "String_Node_Str"+ guestOSType+ "String_Node_Str";
    s_logger.warn(msg);
    throw new CloudRuntimeException(msg);
  }
  final VM template=getVM(conn,guestOsTypeName);
  final VM vm=template.createClone(conn,vmName);
  vm.setIsATemplate(conn,false);
  final Map<VDI,VolumeObjectTO> vdiMap=new HashMap<VDI,VolumeObjectTO>();
  for (  final VolumeObjectTO volume : listVolumeTo) {
    final String vdiUuid=volume.getPath();
    try {
      final VDI vdi=VDI.getByUuid(conn,vdiUuid);
      vdiMap.put(vdi,volume);
    }
 catch (    final Types.UuidInvalid e) {
      s_logger.warn("String_Node_Str" + vdiUuid + "String_Node_Str");
    }
  }
  for (  final Map.Entry<VDI,VolumeObjectTO> entry : vdiMap.entrySet()) {
    final VDI vdi=entry.getKey();
    final VolumeObjectTO volumeTO=entry.getValue();
    final VBD.Record vbdr=new VBD.Record();
    vbdr.VM=vm;
    vbdr.VDI=vdi;
    if (volumeTO.getVolumeType() == Volume.Type.ROOT) {
      vbdr.bootable=true;
      vbdr.unpluggable=false;
    }
 else {
      vbdr.bootable=false;
      vbdr.unpluggable=true;
    }
    vbdr.userdevice="String_Node_Str";
    vbdr.mode=Types.VbdMode.RW;
    vbdr.type=Types.VbdType.DISK;
    Long deviceId=volumeTO.getDeviceId();
    if (deviceId != null && (!isDeviceUsed(conn,vm,deviceId) || deviceId > 3)) {
      vbdr.userdevice=deviceId.toString();
    }
    VBD.create(conn,vbdr);
  }
  return vm;
}