Program: 29897
Project: 29897
Buggy source:
private void createVboxVDIMachine(final Template template,final VirtualCluster cluster,String diskLocation,String name) throws VirtException {
  VirtualBoxManager connect=null;
  try {
    connect=ConnectionManager.connection(getIpAddress());
    IVirtualBox vbox=connect.getVBox();
    String machineName=name;
    IMachine iap=vbox.createMachine(null,machineName,"String_Node_Str",null,true);
    List<IStorageController> lsc=iap.getStorageControllers();
    for (    IStorageController aaa : lsc) {
      System.out.println("String_Node_Str" + aaa.getName());
    }
    iap.getUSBController().setEnabled(false);
    iap.setMemorySize(512L);
    String path=diskLocation + "String_Node_Str" + name+ "String_Node_Str";
    IMedium newm=vbox.createHardDisk("String_Node_Str",path);
    File templateDirLocation=new File(virtualizations.getTemplatesLocation(),template.getName());
    FilenameFilter select=new VDIFileFilter();
    File[] contents=templateDirLocation.listFiles(select);
    if (contents == null || contents.length == 0) {
      throw new VirtException("String_Node_Str" + templateDirLocation.getAbsolutePath());
    }
    if (contents.length != 1) {
      throw new VirtException("String_Node_Str" + templateDirLocation.getAbsolutePath());
    }
    File VDITemplate=contents[0];
    IMedium im=vbox.openMedium(VDITemplate.getAbsolutePath(),DeviceType.HardDisk,AccessMode.ReadWrite,true);
    IProgress prog=im.cloneTo(newm,im.getVariant(),null);
    prog.waitForCompletion(-1);
    IStorageController isctrl=iap.addStorageController("String_Node_Str",StorageBus.SATA);
    INetworkAdapter inadap=iap.getNetworkAdapter(0L);
    inadap.setEnabled(Boolean.FALSE);
    inadap.setAdapterType(NetworkAdapterType.I82540EM);
    inadap.setAttachmentType(NetworkAttachmentType.Bridged);
    String goodPortName=null;
    StringTokenizer portNames=new StringTokenizer(serverPool.getConfig().getPortName(),"String_Node_Str");
    while (portNames.hasMoreTokens()) {
      if (goodPortName != null) {
        break;
      }
      String portName=portNames.nextToken();
      List<IHostNetworkInterface> lll=vbox.getHost().getNetworkInterfaces();
      for (      IHostNetworkInterface imnet : lll) {
        System.out.println("String_Node_Str" + imnet.getName());
        if (imnet.getName().equals(portName)) {
          goodPortName=portName;
          break;
        }
      }
    }
    if (goodPortName == null) {
      throw new VirtException("String_Node_Str" + serverPool.getConfig().getPortName());
    }
    inadap.setBridgedInterface(goodPortName);
    inadap.setEnabled(Boolean.TRUE);
    IStorageController dvdctrl=iap.addStorageController("String_Node_Str",StorageBus.IDE);
    File ISOFile=createISOCustomization(template,cluster,name,diskLocation);
    IMedium cdrommedium=vbox.openMedium(ISOFile.getAbsolutePath(),DeviceType.DVD,AccessMode.ReadOnly,true);
    iap.saveSettings();
    vbox.registerMachine(iap);
    IMachine newMachine=vbox.findMachine(machineName);
    ISession session=connect.openMachineSession(newMachine);
    session.unlockMachine();
    try {
      newMachine.lockMachine(session,LockType.Write);
      IMedium im2=vbox.openMedium(path,DeviceType.HardDisk,AccessMode.ReadWrite,true);
      session.getMachine().attachDevice("String_Node_Str",0,0,DeviceType.HardDisk,im2);
      session.getMachine().attachDevice("String_Node_Str",0,0,DeviceType.DVD,cdrommedium);
      session.getMachine().saveSettings();
    }
  finally {
      session.unlockMachine();
    }
  }
 catch (  Exception e) {
    throw new VirtException(e);
  }
 finally {
    if (connect != null) {
      connect.disconnect();
      connect.cleanup();
    }
  }
}

Fixed version (ground truth):
private void createVboxVDIMachine(final Template template,final VirtualCluster cluster,String diskLocation,String name) throws VirtException {
  VirtualBoxManager connect=null;
  try {
    connect=ConnectionManager.connection(getIpAddress());
    IVirtualBox vbox=connect.getVBox();
    String machineName=name;
    IMachine iap=vbox.createMachine(null,machineName,"String_Node_Str",null,true);
    List<IStorageController> lsc=iap.getStorageControllers();
    for (    IStorageController aaa : lsc) {
      System.out.println("String_Node_Str" + aaa.getName());
    }
    iap.getUSBController().setEnabled(false);
    iap.setMemorySize(512L);
    String path=diskLocation + "String_Node_Str" + name+ "String_Node_Str";
    IMedium newm=vbox.createHardDisk("String_Node_Str",path);
    File templateDirLocation=new File(virtualizations.getTemplatesLocation(),template.getName());
    FilenameFilter select=new VDIFileFilter();
    File[] contents=templateDirLocation.listFiles(select);
    if (contents == null || contents.length == 0) {
      throw new VirtException("String_Node_Str" + templateDirLocation.getAbsolutePath());
    }
    if (contents.length != 1) {
      throw new VirtException("String_Node_Str" + templateDirLocation.getAbsolutePath());
    }
    File VDITemplate=contents[0];
    IMedium im=vbox.openMedium(VDITemplate.getAbsolutePath(),DeviceType.HardDisk,AccessMode.ReadWrite,true);
    IProgress prog=im.cloneTo(newm,im.getVariant(),null);
    prog.waitForCompletion(-1);
    INetworkAdapter inadap=iap.getNetworkAdapter(0L);
    inadap.setEnabled(Boolean.FALSE);
    inadap.setAdapterType(NetworkAdapterType.I82540EM);
    inadap.setAttachmentType(NetworkAttachmentType.Bridged);
    String goodPortName=null;
    StringTokenizer portNames=new StringTokenizer(serverPool.getConfig().getPortName(),"String_Node_Str");
    while (portNames.hasMoreTokens()) {
      if (goodPortName != null) {
        break;
      }
      String portName=portNames.nextToken();
      List<IHostNetworkInterface> lll=vbox.getHost().getNetworkInterfaces();
      for (      IHostNetworkInterface imnet : lll) {
        System.out.println("String_Node_Str" + imnet.getName());
        if (imnet.getName().equals(portName)) {
          goodPortName=portName;
          break;
        }
      }
    }
    if (goodPortName == null) {
      throw new VirtException("String_Node_Str" + serverPool.getConfig().getPortName());
    }
    inadap.setBridgedInterface(goodPortName);
    inadap.setEnabled(Boolean.TRUE);
    File ISOFile=createISOCustomization(template,cluster,name,diskLocation);
    IMedium cdrommedium=vbox.openMedium(ISOFile.getAbsolutePath(),DeviceType.DVD,AccessMode.ReadOnly,true);
    iap.saveSettings();
    vbox.registerMachine(iap);
    IMachine newMachine=vbox.findMachine(machineName);
    ISession session=connect.openMachineSession(newMachine);
    session.unlockMachine();
    try {
      newMachine.lockMachine(session,LockType.Write);
      IMedium im2=vbox.openMedium(path,DeviceType.HardDisk,AccessMode.ReadWrite,true);
      session.getMachine().attachDevice("String_Node_Str",0,0,DeviceType.HardDisk,im2);
      session.getMachine().attachDevice("String_Node_Str",0,0,DeviceType.DVD,cdrommedium);
      session.getMachine().saveSettings();
    }
  finally {
      session.unlockMachine();
    }
  }
 catch (  Exception e) {
    throw new VirtException(e);
  }
 finally {
    if (connect != null) {
      connect.disconnect();
      connect.cleanup();
    }
  }
}