Program: 106615
Project: 106615
Buggy source:
public Commands fullHostSync(final long hostId,StartupRoutingCommand startup){
  Commands commands=new Commands(OnError.Continue);
  Map<Long,AgentVmInfo> infos=convertToInfos(startup);
  final List<? extends VMInstanceVO> vms=_vmDao.listByHostId(hostId);
  s_logger.debug("String_Node_Str" + vms.size() + "String_Node_Str"+ hostId);
  for (  VMInstanceVO vm : vms) {
    AgentVmInfo info=infos.remove(vm.getId());
    VMInstanceVO castedVm=null;
    if (info == null) {
      info=new AgentVmInfo(vm.getInstanceName(),getVmGuru(vm),vm,State.Stopped);
      castedVm=info.guru.findById(vm.getId());
    }
 else {
      castedVm=info.vm;
    }
    HypervisorGuru hvGuru=_hvGuruMgr.getGuru(castedVm.getHypervisorType());
    Command command=compareState(hostId,castedVm,info,true,hvGuru.trackVmHostChange());
    if (command != null) {
      commands.addCommand(command);
    }
  }
  for (  final AgentVmInfo left : infos.values()) {
    boolean found=false;
    for (    VirtualMachineGuru<? extends VMInstanceVO> vmGuru : _vmGurus.values()) {
      VMInstanceVO vm=vmGuru.findByName(left.name);
      if (vm != null) {
        found=true;
        HypervisorGuru hvGuru=_hvGuruMgr.getGuru(vm.getHypervisorType());
        if (hvGuru.trackVmHostChange()) {
          Command command=compareState(hostId,vm,left,true,true);
          if (command != null) {
            commands.addCommand(command);
          }
        }
 else {
          s_logger.warn("String_Node_Str" + left.name + "String_Node_Str"+ vm.getHostId()+ "String_Node_Str"+ hostId);
          commands.addCommand(cleanup(left.name));
        }
        break;
      }
    }
    if (!found) {
      s_logger.warn("String_Node_Str" + left.name);
      commands.addCommand(cleanup(left.name));
    }
  }
  return commands;
}

Fixed version (ground truth):
public Commands fullHostSync(final long hostId,StartupRoutingCommand startup){
  Commands commands=new Commands(OnError.Continue);
  Map<Long,AgentVmInfo> infos=convertToInfos(startup);
  final List<? extends VMInstanceVO> vms=_vmDao.listByHostId(hostId);
  s_logger.debug("String_Node_Str" + vms.size() + "String_Node_Str"+ hostId);
  for (  VMInstanceVO vm : vms) {
    AgentVmInfo info=infos.remove(vm.getId());
    VMInstanceVO castedVm=null;
    if (info == null) {
      info=new AgentVmInfo(vm.getInstanceName(),getVmGuru(vm),vm,State.Stopped);
      castedVm=info.guru.findById(vm.getId());
    }
 else {
      castedVm=info.vm;
    }
    HypervisorGuru hvGuru=_hvGuruMgr.getGuru(castedVm.getHypervisorType());
    Command command=compareState(hostId,castedVm,info,true,hvGuru.trackVmHostChange());
    if (command != null) {
      commands.addCommand(command);
    }
  }
  final List<? extends VMInstanceVO> vmsz=_vmDao.listByHostId(hostId);
  s_logger.debug("String_Node_Str" + vmsz.size() + "String_Node_Str"+ hostId);
  for (  VMInstanceVO vm : vmsz) {
    AgentVmInfo info=infos.remove(vm.getId());
    VMInstanceVO castedVm=null;
    if (info == null) {
      info=new AgentVmInfo(vm.getInstanceName(),getVmGuru(vm),vm,State.Stopped);
      castedVm=info.guru.findById(vm.getId());
    }
 else {
      castedVm=info.vm;
    }
    HypervisorGuru hvGuru=_hvGuruMgr.getGuru(castedVm.getHypervisorType());
    Command command=compareState(hostId,castedVm,info,true,hvGuru.trackVmHostChange());
    if (command != null) {
      commands.addCommand(command);
    }
  }
  for (  final AgentVmInfo left : infos.values()) {
    boolean found=false;
    for (    VirtualMachineGuru<? extends VMInstanceVO> vmGuru : _vmGurus.values()) {
      VMInstanceVO vm=vmGuru.findByName(left.name);
      if (vm != null) {
        found=true;
        HypervisorGuru hvGuru=_hvGuruMgr.getGuru(vm.getHypervisorType());
        if (hvGuru.trackVmHostChange()) {
          Command command=compareState(hostId,vm,left,true,true);
          if (command != null) {
            commands.addCommand(command);
          }
        }
 else {
          s_logger.warn("String_Node_Str" + left.name + "String_Node_Str"+ vm.getHostId()+ "String_Node_Str"+ hostId);
          commands.addCommand(cleanup(left.name));
        }
        break;
      }
    }
    if (!found) {
      s_logger.warn("String_Node_Str" + left.name);
      commands.addCommand(cleanup(left.name));
    }
  }
  return commands;
}