Program: 46495
Project: 46495
Buggy source:
public void connectNic(Vm vm,NicOption option) throws VmException {
  checkConnected();
  if (lock.tryLock()) {
    try {
      if (option.getNic().equals(ORIGINAL_NETWORK_CONFIG)) {
        VBoxConfig cfg=new VBoxConfig(vm.getVmContainer(),vm.getRuntimeContainer());
        try {
          cfg.load();
        }
 catch (        CubeException e) {
          throw new VmException("String_Node_Str",e);
        }
        ISession session=mgr.getSessionObject();
        IMachine machine=getIMachineReference(vm.getId());
        machine.lockMachine(session,LockType.Shared);
        IMachine mutable=session.getMachine();
        addNetworkIface(0,cfg.getOption(VBoxOption.Nic1),cfg.getOption(VBoxOption.Nic1Bridge),cfg.getOption(VBoxOption.Nic1Mac),mutable);
        addNetworkIface(1,cfg.getOption(VBoxOption.Nic2),cfg.getOption(VBoxOption.Nic2Bridge),cfg.getOption(VBoxOption.Nic2Mac),mutable);
        addNetworkIface(2,cfg.getOption(VBoxOption.Nic3),cfg.getOption(VBoxOption.Nic3Bridge),cfg.getOption(VBoxOption.Nic3Mac),mutable);
        addNetworkIface(3,cfg.getOption(VBoxOption.Nic4),cfg.getOption(VBoxOption.Nic4Bridge),cfg.getOption(VBoxOption.Nic4Mac),mutable);
        mutable.saveSettings();
        session.unlockMachine();
      }
 else {
        ISession session=mgr.getSessionObject();
        IMachine machine=getIMachineReference(vm.getId());
        machine.lockMachine(session,LockType.Shared);
        IMachine mutable=session.getMachine();
        for (long nic=0l; nic < 4l; nic++) {
          mutable.getNetworkAdapter(nic).setCableConnected(false);
          mutable.getNetworkAdapter(nic).setEnabled(false);
        }
        INetworkAdapter na=mutable.getNetworkAdapter(0l);
        na.setAttachmentType(NetworkAttachmentType.Bridged);
        na.setBridgedInterface(option.getNic());
        na.setEnabled(true);
        na.setCableConnected(true);
        na.setPromiscModePolicy(NetworkAdapterPromiscModePolicy.AllowAll);
        mutable.saveSettings();
        session.unlockMachine();
      }
    }
 catch (    Exception e) {
      throw new VmException("String_Node_Str" + option.getNic() + "String_Node_Str",e);
    }
 finally {
      unlockSession();
      lock.unlock();
    }
  }
 else {
    LOG.debug("String_Node_Str");
  }
}

Fixed version (ground truth):
public void connectNic(Vm vm,NicOption option) throws VmException {
  checkConnected();
  if (lock.tryLock()) {
    try {
      if (option.getNic().equals(ORIGINAL_NETWORK_CONFIG)) {
        VBoxConfig cfg=new VBoxConfig(vm.getVmContainer(),vm.getRuntimeContainer());
        try {
          cfg.load();
        }
 catch (        CubeException e) {
          throw new VmException("String_Node_Str",e);
        }
        ISession session=mgr.getSessionObject();
        IMachine machine=getIMachineReference(vm.getId());
        machine.lockMachine(session,LockType.Shared);
        IMachine mutable=session.getMachine();
        addNetworkIface(0,cfg.getOption(VBoxOption.Nic1),cfg.getOption(VBoxOption.Nic1Bridge),cfg.getOption(VBoxOption.Nic1Mac),mutable);
        addNetworkIface(1,cfg.getOption(VBoxOption.Nic2),cfg.getOption(VBoxOption.Nic2Bridge),cfg.getOption(VBoxOption.Nic2Mac),mutable);
        addNetworkIface(2,cfg.getOption(VBoxOption.Nic3),cfg.getOption(VBoxOption.Nic3Bridge),cfg.getOption(VBoxOption.Nic3Mac),mutable);
        addNetworkIface(3,cfg.getOption(VBoxOption.Nic4),cfg.getOption(VBoxOption.Nic4Bridge),cfg.getOption(VBoxOption.Nic4Mac),mutable);
        mutable.saveSettings();
        session.unlockMachine();
      }
 else {
        ISession session=mgr.getSessionObject();
        IMachine machine=getIMachineReference(vm.getId());
        machine.lockMachine(session,LockType.Shared);
        IMachine mutable=session.getMachine();
        for (long nic=1l; nic < 4l; nic++) {
          mutable.getNetworkAdapter(nic).setCableConnected(false);
          mutable.getNetworkAdapter(nic).setEnabled(false);
        }
        INetworkAdapter na=mutable.getNetworkAdapter(0l);
        na.setAttachmentType(NetworkAttachmentType.Bridged);
        na.setBridgedInterface(option.getNic());
        na.setEnabled(true);
        na.setCableConnected(true);
        na.setPromiscModePolicy(NetworkAdapterPromiscModePolicy.AllowAll);
        mutable.saveSettings();
        session.unlockMachine();
      }
    }
 catch (    Exception e) {
      throw new VmException("String_Node_Str" + option.getNic() + "String_Node_Str",e);
    }
 finally {
      unlockSession();
      lock.unlock();
    }
  }
 else {
    LOG.debug("String_Node_Str");
  }
}