Program: 12172
Project: 12172
Buggy source:
/** 
 * Implements the Soar-EpMem API <p>episodic_memory.cpp:5238:void epmem_respond_to_cmd( agent *my_agent )
 * @throws SoarException 
 * @throws SQLException 
 */
private void epmem_respond_to_cmd() throws SoarException, SQLException {
  if (db == null) {
    epmem_init_db();
  }
  IdentifierImpl state=decider.bottom_goal;
  List<WmeImpl> wmes;
  List<WmeImpl> cmds;
  Set<WmeImpl> cue_wmes=Sets.newHashSet();
  List<SymbolTriple> meta_wmes=Lists.newArrayList();
  List<SymbolTriple> retrieval_wmes=Lists.newArrayList();
  long retrieve=0;
  SymbolImpl next=null;
  SymbolImpl previous=null;
  SymbolImpl query=null;
  SymbolImpl neg_query=null;
  List<Long> prohibit=Lists.newLinkedList();
  long before=0;
  long after=0;
  Set<SymbolImpl> currents=Sets.newHashSet();
  boolean good_cue=false;
  int path=0;
  long wme_count;
  boolean new_cue;
  boolean do_wm_phase=false;
  while (state != null) {
    final EpisodicMemoryStateInfo epmem_info=epmem_info(state);
    new_cue=false;
    wme_count=0;
    cmds=null;
{
      Marker tc=DefaultMarker.create();
      Queue<SymbolImpl> syms=new LinkedList<SymbolImpl>();
      SymbolImpl parent_sym;
      syms.add(epmem_info.epmem_cmd_header);
      while (!syms.isEmpty()) {
        parent_sym=syms.poll();
        wmes=epmem_get_augs_of_id(parent_sym,tc);
{
          for (          final WmeImpl wme : wmes) {
            wme_count++;
            if (wme.timetag > epmem_info.last_cmd_time) {
              new_cue=true;
              epmem_info.last_cmd_time=wme.timetag;
            }
            if (wme.value.asIdentifier() != null) {
              syms.add(wme.value.asIdentifier());
            }
          }
          if (cmds == null) {
            cmds=wmes;
          }
 else {
            wmes=null;
          }
        }
      }
      if (epmem_info.last_cmd_count != wme_count) {
        new_cue=true;
        epmem_info.last_cmd_count=wme_count;
      }
      if (new_cue) {
        epmem_clear_result(state);
        do_wm_phase=true;
      }
    }
    if (new_cue && wme_count != 0) {
      _epmem_respond_to_cmd_parse(cmds,good_cue,path,retrieve,next,previous,query,neg_query,prohibit,before,after,currents,cue_wmes);
      retrieval_wmes.clear();
      meta_wmes.clear();
      if (good_cue) {
        if (path == 1) {
          epmem_install_memory(state,retrieve,meta_wmes,retrieval_wmes);
          stats.ncbr.set(stats.ncbr.get() + 1L);
        }
 else         if (path == 2) {
          if (next != null) {
            epmem_install_memory(state,epmem_next_episode(epmem_info.last_memory),meta_wmes,retrieval_wmes);
            stats.nexts.set(stats.nexts.get() + 1L);
          }
 else {
            epmem_install_memory(state,epmem_previous_episode(epmem_info.last_memory),meta_wmes,retrieval_wmes);
            stats.prevs.set(stats.prevs.get() + 1L);
          }
          if (epmem_info.last_memory == EPMEM_MEMID_NONE) {
            epmem_buffer_add_wme(meta_wmes,epmem_info.epmem_result_header,predefinedSyms.epmem_sym_failure,((next != null) ? (next) : (previous)));
          }
 else {
            epmem_buffer_add_wme(meta_wmes,epmem_info.epmem_result_header,predefinedSyms.epmem_sym_success,((next != null) ? (next) : (previous)));
          }
        }
 else         if (path == 3) {
          epmem_process_query(state,query,neg_query,prohibit,before,after,currents,cue_wmes,meta_wmes,retrieval_wmes);
          stats.cbr.set(stats.cbr.get() + 1L);
        }
      }
 else {
        epmem_buffer_add_wme(meta_wmes,epmem_info.epmem_result_header,predefinedSyms.epmem_sym_status,predefinedSyms.epmem_sym_bad_cmd);
      }
      prohibit.clear();
      if (!retrieval_wmes.isEmpty() || !meta_wmes.isEmpty()) {
        epmem_process_buffered_wmes(state,cue_wmes,meta_wmes,retrieval_wmes);
        do_wm_phase=true;
      }
      cue_wmes.clear();
    }
 else {
    }
    if (cmds != null) {
      cmds=null;
    }
    state=state.goalInfo.higher_goal;
  }
  if (do_wm_phase) {
    decider.do_working_memory_phase();
  }
}

Fixed version (ground truth):
/** 
 * Implements the Soar-EpMem API <p>episodic_memory.cpp:5238:void epmem_respond_to_cmd( agent *my_agent )
 * @throws SoarException 
 * @throws SQLException 
 */
private void epmem_respond_to_cmd() throws SoarException, SQLException {
  if (db == null) {
    epmem_init_db();
  }
  IdentifierImpl state=decider.bottom_goal;
  List<WmeImpl> wmes;
  List<WmeImpl> cmds;
  Set<WmeImpl> cue_wmes=Sets.newHashSet();
  List<SymbolTriple> meta_wmes=Lists.newArrayList();
  List<SymbolTriple> retrieval_wmes=Lists.newArrayList();
  ByRef<Long> retrieve=ByRef.create(0L);
  SymbolImpl next=null;
  SymbolImpl previous=null;
  SymbolImpl query=null;
  SymbolImpl neg_query=null;
  List<Long> prohibit=Lists.newLinkedList();
  ByRef<Long> before=ByRef.create(0L);
  ByRef<Long> after=ByRef.create(0L);
  Set<SymbolImpl> currents=Sets.newHashSet();
  ByRef<Boolean> good_cue=ByRef.create(false);
  ByRef<Integer> path=ByRef.create(0);
  long wme_count;
  boolean new_cue;
  boolean do_wm_phase=false;
  while (state != null) {
    final EpisodicMemoryStateInfo epmem_info=epmem_info(state);
    new_cue=false;
    wme_count=0;
    cmds=null;
{
      Marker tc=DefaultMarker.create();
      Queue<SymbolImpl> syms=new LinkedList<SymbolImpl>();
      SymbolImpl parent_sym;
      syms.add(epmem_info.epmem_cmd_header);
      while (!syms.isEmpty()) {
        parent_sym=syms.poll();
        wmes=epmem_get_augs_of_id(parent_sym,tc);
{
          for (          final WmeImpl wme : wmes) {
            wme_count++;
            if (wme.timetag > epmem_info.last_cmd_time) {
              new_cue=true;
              epmem_info.last_cmd_time=wme.timetag;
            }
            if (wme.value.asIdentifier() != null) {
              syms.add(wme.value.asIdentifier());
            }
          }
          if (cmds == null) {
            cmds=wmes;
          }
 else {
            wmes=null;
          }
        }
      }
      if (epmem_info.last_cmd_count != wme_count) {
        new_cue=true;
        epmem_info.last_cmd_count=wme_count;
      }
      if (new_cue) {
        epmem_clear_result(state);
        do_wm_phase=true;
      }
    }
    if (new_cue && wme_count != 0) {
      _epmem_respond_to_cmd_parse(cmds,good_cue,path,retrieve,next,previous,query,neg_query,prohibit,before,after,currents,cue_wmes);
      retrieval_wmes.clear();
      meta_wmes.clear();
      if (good_cue.value) {
        if (path.value == 1) {
          epmem_install_memory(state,retrieve.value,meta_wmes,retrieval_wmes);
          stats.ncbr.set(stats.ncbr.get() + 1L);
        }
 else         if (path.value == 2) {
          if (next != null) {
            epmem_install_memory(state,epmem_next_episode(epmem_info.last_memory),meta_wmes,retrieval_wmes);
            stats.nexts.set(stats.nexts.get() + 1L);
          }
 else {
            epmem_install_memory(state,epmem_previous_episode(epmem_info.last_memory),meta_wmes,retrieval_wmes);
            stats.prevs.set(stats.prevs.get() + 1L);
          }
          if (epmem_info.last_memory == EPMEM_MEMID_NONE) {
            epmem_buffer_add_wme(meta_wmes,epmem_info.epmem_result_header,predefinedSyms.epmem_sym_failure,((next != null) ? (next) : (previous)));
          }
 else {
            epmem_buffer_add_wme(meta_wmes,epmem_info.epmem_result_header,predefinedSyms.epmem_sym_success,((next != null) ? (next) : (previous)));
          }
        }
 else         if (path.value == 3) {
          epmem_process_query(state,query,neg_query,prohibit,before.value,after.value,currents,cue_wmes,meta_wmes,retrieval_wmes);
          stats.cbr.set(stats.cbr.get() + 1L);
        }
      }
 else {
        epmem_buffer_add_wme(meta_wmes,epmem_info.epmem_result_header,predefinedSyms.epmem_sym_status,predefinedSyms.epmem_sym_bad_cmd);
      }
      prohibit.clear();
      if (!retrieval_wmes.isEmpty() || !meta_wmes.isEmpty()) {
        epmem_process_buffered_wmes(state,cue_wmes,meta_wmes,retrieval_wmes);
        do_wm_phase=true;
      }
      cue_wmes.clear();
    }
 else {
    }
    if (cmds != null) {
      cmds=null;
    }
    state=state.goalInfo.higher_goal;
  }
  if (do_wm_phase) {
    decider.do_working_memory_phase();
  }
}