Program: 106056
Project: 106056
Buggy source:
public Outcome<VirtualMachine> addVmToNetworkThroughJobQueue(final VirtualMachine vm,final Network network,final NicProfile requested){
  final CallContext context=CallContext.current();
  final User user=context.getCallingUser();
  final Account account=context.getCallingAccount();
  Object[] result=Transaction.execute(new TransactionCallback<Object[]>(){
    @Override public Object[] doInTransaction(    TransactionStatus status){
      List<VmWorkJobVO> pendingWorkJobs=_workJobDao.listPendingWorkJobs(VirtualMachine.Type.Instance,vm.getId(),VmWorkAddVmToNetwork.class.getName());
      VmWorkJobVO workJob=null;
      if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
        assert(pendingWorkJobs.size() == 1);
        workJob=pendingWorkJobs.get(0);
      }
 else {
        workJob=new VmWorkJobVO(context.getContextId());
        workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
        workJob.setCmd(VmWorkAddVmToNetwork.class.getName());
        workJob.setAccountId(account.getId());
        workJob.setUserId(user.getId());
        workJob.setVmType(vm.getType());
        workJob.setVmInstanceId(vm.getId());
        workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId());
        VmWorkAddVmToNetwork workInfo=new VmWorkAddVmToNetwork(user.getId(),account.getId(),vm.getId(),VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER,network,requested);
        workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
        _jobMgr.submitAsyncJob(workJob,VmWorkConstants.VM_WORK_QUEUE,vm.getId());
      }
      return new Object[]{workJob,new Long(workJob.getId())};
    }
  }
);
  final long jobId=(Long)result[1];
  AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
  return new VmJobVirtualMachineOutcome((VmWorkJobVO)result[0],vm.getId());
}

Fixed version (ground truth):
public Outcome<VirtualMachine> addVmToNetworkThroughJobQueue(final VirtualMachine vm,final Network network,final NicProfile requested){
  final CallContext context=CallContext.current();
  final User user=context.getCallingUser();
  final Account account=context.getCallingAccount();
  Object[] result=Transaction.execute(new TransactionCallback<Object[]>(){
    @Override public Object[] doInTransaction(    TransactionStatus status){
      List<VmWorkJobVO> pendingWorkJobs=_workJobDao.listPendingWorkJobs(VirtualMachine.Type.Instance,vm.getId(),VmWorkAddVmToNetwork.class.getName());
      VmWorkJobVO workJob=null;
      if (pendingWorkJobs != null && pendingWorkJobs.size() > 0) {
        assert(pendingWorkJobs.size() == 1);
        workJob=pendingWorkJobs.get(0);
      }
 else {
        workJob=new VmWorkJobVO(context.getContextId());
        workJob.setDispatcher(VmWorkConstants.VM_WORK_JOB_DISPATCHER);
        workJob.setCmd(VmWorkAddVmToNetwork.class.getName());
        workJob.setAccountId(account.getId());
        workJob.setUserId(user.getId());
        workJob.setVmType(vm.getType());
        workJob.setVmInstanceId(vm.getId());
        workJob.setRelated(AsyncJobExecutionContext.getOriginJobContextId());
        VmWorkAddVmToNetwork workInfo=new VmWorkAddVmToNetwork(user.getId(),account.getId(),vm.getId(),VirtualMachineManagerImpl.VM_WORK_JOB_HANDLER,network.getId(),requested);
        workJob.setCmdInfo(VmWorkSerializer.serialize(workInfo));
        _jobMgr.submitAsyncJob(workJob,VmWorkConstants.VM_WORK_QUEUE,vm.getId());
      }
      return new Object[]{workJob,new Long(workJob.getId())};
    }
  }
);
  final long jobId=(Long)result[1];
  AsyncJobExecutionContext.getCurrentExecutionContext().joinJob(jobId);
  return new VmJobVirtualMachineOutcome((VmWorkJobVO)result[0],vm.getId());
}