Program: 46492
Project: 46492
Buggy source:
public void connectNic(Vm vm,NicOption option) throws VmException {
  checkConnected();
  if (lock.tryLock()) {
    try {
      if (option.getNic().equals(ORIGINAL_NETWORK_CONFIG)) {
        vm.setNetworkState(VmNetworkState.CUBE);
        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 {
        vm.setNetworkState(VmNetworkState.LOCAL);
        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.setPromiscModePolicy(NetworkAdapterPromiscModePolicy.AllowAll);
        mutable.saveSettings();
        na.setCableConnected(true);
        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)) {
        vm.setNetworkState(VmNetworkState.CUBE);
        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 {
        vm.setNetworkState(VmNetworkState.LOCAL);
        ISession session=mgr.getSessionObject();
        IMachine machine=getIMachineReference(vm.getId());
        machine.lockMachine(session,LockType.Shared);
        IMachine mutable=session.getMachine();
        LOG.debug("String_Node_Str");
        for (long nic=1l; nic <= 3l; nic++) {
          INetworkAdapter na=mutable.getNetworkAdapter(nic);
          na.setCableConnected(false);
          na.setAttachmentType(NetworkAttachmentType.Null);
          na.setEnabled(false);
        }
        LOG.debug("String_Node_Str");
        INetworkAdapter na=mutable.getNetworkAdapter(0l);
        na.setEnabled(true);
        na.setAttachmentType(NetworkAttachmentType.Bridged);
        na.setBridgedInterface(option.getNic());
        na.setPromiscModePolicy(NetworkAdapterPromiscModePolicy.AllowAll);
        LOG.debug("String_Node_Str");
        na.setCableConnected(true);
        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");
  }
}