Program: 49012
Project: 49012
Buggy source:
public void callInternal() throws Exception {
  final VcVirtualMachine template=VcCache.get(vmSchema.diskSchema.getParent());
  VcSnapshot snap=template.getSnapshotByName(vmSchema.diskSchema.getParentSnap());
  ConfigSpecImpl configSpec=new ConfigSpecImpl();
  HashMap<String,Disk.Operation> diskMap=new HashMap<String,Disk.Operation>();
  final VcVirtualMachine.CreateSpec vmSpec=new VcVirtualMachine.CreateSpec(newVmName,snap,targetRp,targetDs,vmFolder,linkedClone,configSpec);
  List<VcHost> hostList=new ArrayList<VcHost>();
  List<DiskCreateSpec> addDisks=DiskSchemaUtil.getDisksToAdd(hostList,targetRp,targetDs,vmSchema.diskSchema,diskMap);
  vcVm=template.cloneVm(vmSpec,null);
  if (host != null) {
    vcVm.disableDrs();
  }
  DiskCreateSpec[] tmpAddDisks=new DiskCreateSpec[addDisks.size()];
  tmpAddDisks=addDisks.toArray(tmpAddDisks);
  if (hostList.size() > 0 && !hostList.contains(vcVm.getHost())) {
    vcVm.migrate(hostList.get(0));
  }
  vcVm.changeDisks(null,tmpAddDisks);
  if (linkedClone) {
    ArrayList<DeviceId> disksToPromote=new ArrayList<DeviceId>();
    for (    Entry<String,Disk.Operation> entry : diskMap.entrySet()) {
      if (entry.getValue() == Disk.Operation.PROMOTE) {
        disksToPromote.add(new DeviceId(entry.getKey()));
      }
    }
    if (disksToPromote.size() >= 1) {
      vcVm.promoteDisks(disksToPromote.toArray(new DeviceId[0]));
    }
  }
  ConfigSpecImpl newConfigSpec=new ConfigSpecImpl();
  NetworkSchemaUtil.setNetworkSchema(newConfigSpec,targetRp.getVcCluster(),vmSchema.networkSchema);
  ResourceSchemaUtil.setResourceSchema(newConfigSpec,vmSchema.resourceSchema);
  vcVm.reconfigure(newConfigSpec);
  if (bootupConfigs != null) {
    vcVm.setGuestConfigs(bootupConfigs);
  }
  if (prePowerOn != null) {
    prePowerOn.setVm(vcVm);
    prePowerOn.call();
  }
  vcVm.powerOn(host);
  if (postPowerOn != null) {
    postPowerOn.setVm(vcVm);
    postPowerOn.call();
  }
}

Fixed version (ground truth):
public void callInternal() throws Exception {
  final VcVirtualMachine template=VcCache.get(vmSchema.diskSchema.getParent());
  VcSnapshot snap=template.getSnapshotByName(vmSchema.diskSchema.getParentSnap());
  ConfigSpecImpl configSpec=new ConfigSpecImpl();
  HashMap<String,Disk.Operation> diskMap=new HashMap<String,Disk.Operation>();
  final VcVirtualMachine.CreateSpec vmSpec=new VcVirtualMachine.CreateSpec(newVmName,snap,targetRp,targetDs,vmFolder,linkedClone,configSpec);
  List<VcHost> hostList=new ArrayList<VcHost>();
  List<DiskCreateSpec> addDisks=DiskSchemaUtil.getDisksToAdd(hostList,targetRp,targetDs,vmSchema.diskSchema,diskMap);
  vcVm=template.cloneVm(vmSpec,null);
  if (host != null) {
    vcVm.disableDrs();
  }
  DiskCreateSpec[] tmpAddDisks=new DiskCreateSpec[addDisks.size()];
  tmpAddDisks=addDisks.toArray(tmpAddDisks);
  if (hostList.size() > 0 && !hostList.contains(vcVm.getHost())) {
    vcVm.migrate(hostList.get(0));
  }
  vcVm.changeDisks(null,tmpAddDisks);
  if (linkedClone) {
    ArrayList<DeviceId> disksToPromote=new ArrayList<DeviceId>();
    for (    Entry<String,Disk.Operation> entry : diskMap.entrySet()) {
      if (entry.getValue() == Disk.Operation.PROMOTE) {
        disksToPromote.add(new DeviceId(entry.getKey()));
      }
    }
    if (disksToPromote.size() >= 1) {
      vcVm.promoteDisks(disksToPromote.toArray(new DeviceId[0]));
    }
  }
  ConfigSpecImpl newConfigSpec=new ConfigSpecImpl();
  NetworkSchemaUtil.setNetworkSchema(newConfigSpec,targetRp.getVcCluster(),vmSchema.networkSchema,vcVm);
  ResourceSchemaUtil.setResourceSchema(newConfigSpec,vmSchema.resourceSchema);
  vcVm.reconfigure(newConfigSpec);
  if (bootupConfigs != null) {
    vcVm.setGuestConfigs(bootupConfigs);
  }
  if (prePowerOn != null) {
    prePowerOn.setVm(vcVm);
    prePowerOn.call();
  }
  vcVm.powerOn(host);
  if (postPowerOn != null) {
    postPowerOn.setVm(vcVm);
    postPowerOn.call();
  }
}