Program: 106929
Project: 106929
Buggy source:
@DB protected <T extends VMInstanceVO>Ternary<T,ReservationContext,ItWorkVO> changeToStartState(VirtualMachineGuru<T> vmGuru,T vm,User caller,Account account) throws ConcurrentOperationException {
  long vmId=vm.getId();
  ItWorkVO work=new ItWorkVO(UUID.randomUUID().toString(),_nodeId,State.Starting,vm.getType(),vm.getId());
  int retry=_lockStateRetry;
  while (retry-- != 0) {
    Transaction txn=Transaction.currentTxn();
    txn.start();
    try {
      try {
        if (stateTransitTo(vm,Event.StartRequested,null,work.getId())) {
          Journal journal=new Journal.LogJournal("String_Node_Str" + vm,s_logger);
          work=_workDao.persist(work);
          ReservationContextImpl context=new ReservationContextImpl(work.getId(),journal,caller,account);
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + vm + "String_Node_Str"+ work.getId());
          }
          return new Ternary<T,ReservationContext,ItWorkVO>(vmGuru.findById(vmId),context,work);
        }
      }
 catch (      NoTransitionException e) {
        throw new CloudRuntimeException(e.getMessage());
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + vm);
      }
      VMInstanceVO instance=_vmDao.findById(vmId);
      if (instance == null) {
        throw new ConcurrentOperationException("String_Node_Str" + vm);
      }
      State state=instance.getState();
      if (state == State.Running) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + vm);
        }
        return null;
      }
      if (state.isTransitional()) {
        if (!checkWorkItems(vm,state)) {
          throw new ConcurrentOperationException("String_Node_Str" + vm);
        }
 else {
          continue;
        }
      }
      if (state != State.Stopped) {
        s_logger.debug("String_Node_Str" + vm + "String_Node_Str"+ state);
        return null;
      }
    }
  finally {
      txn.commit();
    }
  }
  throw new ConcurrentOperationException("String_Node_Str" + vm);
}

Fixed version (ground truth):
@DB protected <T extends VMInstanceVO>Ternary<T,ReservationContext,ItWorkVO> changeToStartState(VirtualMachineGuru<T> vmGuru,T vm,User caller,Account account) throws ConcurrentOperationException {
  long vmId=vm.getId();
  ItWorkVO work=new ItWorkVO(UUID.randomUUID().toString(),_nodeId,State.Starting,vm.getType(),vm.getId());
  int retry=_lockStateRetry;
  while (retry-- != 0) {
    Transaction txn=Transaction.currentTxn();
    txn.start();
    try {
      try {
        if (stateTransitTo(vm,Event.StartRequested,null,work.getId())) {
          Journal journal=new Journal.LogJournal("String_Node_Str" + vm,s_logger);
          work=_workDao.persist(work);
          ReservationContextImpl context=new ReservationContextImpl(work.getId(),journal,caller,account);
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + vm + "String_Node_Str"+ work.getId());
          }
          return new Ternary<T,ReservationContext,ItWorkVO>(vmGuru.findById(vmId),context,work);
        }
      }
 catch (      NoTransitionException e) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + e.getMessage());
        }
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + vm);
      }
      VMInstanceVO instance=_vmDao.findById(vmId);
      if (instance == null) {
        throw new ConcurrentOperationException("String_Node_Str" + vm);
      }
      State state=instance.getState();
      if (state == State.Running) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + vm);
        }
        return null;
      }
      if (state.isTransitional()) {
        if (!checkWorkItems(vm,state)) {
          throw new ConcurrentOperationException("String_Node_Str" + vm);
        }
 else {
          continue;
        }
      }
      if (state != State.Stopped) {
        s_logger.debug("String_Node_Str" + vm + "String_Node_Str"+ state);
        return null;
      }
    }
  finally {
      txn.commit();
    }
  }
  throw new ConcurrentOperationException("String_Node_Str" + vm);
}