Program: 12213
Project: 12213
Buggy source:
/** 
 * <p>semantic_memory.cpp:2702:smem_respond_to_cmd
 * @param store_only
 * @throws SQLException
 * @throws SoarException
 */
void smem_respond_to_cmd(boolean store_only) throws SQLException, SoarException {
  IdentifierImpl state=decider.bottom_goal;
  List<WmeImpl> wmes=new LinkedList<WmeImpl>();
  List<WmeImpl> cmds=null;
  IdentifierImpl query;
  IdentifierImpl retrieve;
  List<IdentifierImpl> prohibit=new LinkedList<IdentifierImpl>();
  List<IdentifierImpl> store=new LinkedList<IdentifierImpl>();
  path_type path=path_type.blank_slate;
  final int time_slot=((store_only) ? (1) : (0));
  long wme_count=0;
  boolean new_cue=false;
  Marker tc;
  IdentifierImpl parent_sym=null;
  final Queue<IdentifierImpl> syms=new ArrayDeque<IdentifierImpl>();
  int parent_level=0;
  final Queue<Integer> levels=new ArrayDeque<Integer>();
  while (state != null) {
    final SemanticMemoryStateInfo smem_info=smem_info(state);
    new_cue=false;
    wme_count=0;
    cmds=null;
{
      tc=DefaultMarker.create();
      syms.add(smem_info.smem_cmd_header);
      levels.add(0);
      while (!syms.isEmpty()) {
        parent_sym=syms.remove();
        parent_level=levels.remove();
        wmes=smem_get_direct_augs_of_id(parent_sym,tc);
{
          for (          WmeImpl w_p : wmes) {
            if (((store_only) && ((parent_level != 0) || ((w_p.attr != predefinedSyms.smem_sym_query) && (w_p.attr != predefinedSyms.smem_sym_retrieve)))) || ((!store_only) && ((parent_level != 0) || (w_p.attr != predefinedSyms.smem_sym_store)))) {
              wme_count++;
              if (w_p.timetag > smem_info.last_cmd_time[time_slot]) {
                new_cue=true;
                smem_info.last_cmd_time[time_slot]=w_p.timetag;
              }
              if ((w_p.value.asIdentifier() != null) && (parent_level == 0) && ((w_p.attr == predefinedSyms.smem_sym_query) || (w_p.attr == predefinedSyms.smem_sym_store))) {
                syms.add(w_p.value.asIdentifier());
                levels.add(parent_level + 1);
              }
            }
          }
          if (cmds == null) {
            cmds=wmes;
          }
 else {
            wmes=null;
          }
        }
      }
      if (smem_info.last_cmd_count[time_slot] != wme_count) {
        new_cue=true;
        smem_info.last_cmd_count[time_slot]=wme_count;
      }
      if (new_cue) {
        smem_info.cue_wmes.clear();
        smem_clear_result(state);
        smem_made_changes=true;
      }
    }
    if (new_cue && wme_count != 0) {
      retrieve=null;
      query=null;
      store.clear();
      prohibit.clear();
      path=path_type.blank_slate;
      for (      WmeImpl w_p : cmds) {
        smem_info.cue_wmes.add(w_p);
        if (path != path_type.cmd_bad) {
          if (w_p.attr == predefinedSyms.smem_sym_retrieve) {
            if ((w_p.value.asIdentifier() != null) && (path == path_type.blank_slate)) {
              retrieve=w_p.value.asIdentifier();
              path=path_type.cmd_retrieve;
            }
 else {
              path=path_type.cmd_bad;
            }
          }
 else           if (w_p.attr == predefinedSyms.smem_sym_query) {
            if ((w_p.value.asIdentifier() != null) && ((path == path_type.blank_slate) || (path == path_type.cmd_query)) && (query == null)) {
              query=w_p.value.asIdentifier();
              path=path_type.cmd_query;
            }
 else {
              path=path_type.cmd_bad;
            }
          }
 else           if (w_p.attr == predefinedSyms.smem_sym_prohibit) {
            if ((w_p.value.asIdentifier() != null) && ((path == path_type.blank_slate) || (path == path_type.cmd_query)) && (w_p.value.asIdentifier().smem_lti != 0)) {
              prohibit.add(w_p.value.asIdentifier());
              path=path_type.cmd_query;
            }
 else {
              path=path_type.cmd_bad;
            }
          }
 else           if (w_p.attr == predefinedSyms.smem_sym_store) {
            if ((w_p.value.asIdentifier() != null) && ((path == path_type.blank_slate) || (path == path_type.cmd_store))) {
              store.add(w_p.value.asIdentifier());
              path=path_type.cmd_store;
            }
 else {
              path=path_type.cmd_bad;
            }
          }
 else {
            path=path_type.cmd_bad;
          }
        }
      }
      if ((path == path_type.cmd_query) && (query == null)) {
        path=path_type.cmd_bad;
      }
      if (path == path_type.blank_slate) {
        path=path_type.cmd_bad;
      }
      if (path != path_type.cmd_bad) {
        smem_attach();
        if (path == path_type.cmd_retrieve) {
          if (retrieve.smem_lti == 0) {
            smem_add_meta_wme(state,smem_info.smem_result_header,predefinedSyms.smem_sym_failure,retrieve);
          }
 else {
            smem_add_meta_wme(state,smem_info.smem_result_header,predefinedSyms.smem_sym_success,retrieve);
            smem_install_memory(state,retrieve.smem_lti,retrieve);
          }
        }
 else         if (path == path_type.cmd_query) {
          final Set<Long> prohibit_lti=new HashSet<Long>();
          for (          IdentifierImpl sym_p : prohibit) {
            prohibit_lti.add(sym_p.smem_lti);
          }
          smem_process_query(state,query,prohibit_lti);
        }
 else         if (path == path_type.cmd_store) {
          if (true) {
            db.begin.executeUpdate();
          }
          for (          IdentifierImpl sym_p : store) {
            smem_soar_store(sym_p);
            smem_add_meta_wme(state,smem_info.smem_result_header,predefinedSyms.smem_sym_success,sym_p);
          }
          if (true) {
            db.commit.executeUpdate();
          }
        }
      }
 else {
        smem_add_meta_wme(state,smem_info.smem_result_header,predefinedSyms.smem_sym_bad_cmd,smem_info.smem_cmd_header);
      }
    }
 else {
    }
    cmds=null;
    state=state.higher_goal;
  }
}

Fixed version (ground truth):
/** 
 * <p>semantic_memory.cpp:2702:smem_respond_to_cmd
 * @param store_only
 * @throws SQLException
 * @throws SoarException
 */
void smem_respond_to_cmd(boolean store_only) throws SQLException, SoarException {
  IdentifierImpl state=decider.bottom_goal;
  List<WmeImpl> wmes=new LinkedList<WmeImpl>();
  List<WmeImpl> cmds=null;
  IdentifierImpl query;
  IdentifierImpl retrieve;
  List<IdentifierImpl> prohibit=new LinkedList<IdentifierImpl>();
  List<IdentifierImpl> store=new LinkedList<IdentifierImpl>();
  path_type path=path_type.blank_slate;
  final int time_slot=((store_only) ? (1) : (0));
  long wme_count=0;
  boolean new_cue=false;
  Marker tc;
  IdentifierImpl parent_sym=null;
  final Queue<IdentifierImpl> syms=new ArrayDeque<IdentifierImpl>();
  int parent_level=0;
  final Queue<Integer> levels=new ArrayDeque<Integer>();
  while (state != null) {
    final SemanticMemoryStateInfo smem_info=smem_info(state);
    new_cue=false;
    wme_count=0;
    cmds=null;
{
      tc=DefaultMarker.create();
      syms.add(smem_info.smem_cmd_header);
      levels.add(0);
      while (!syms.isEmpty()) {
        parent_sym=syms.remove();
        parent_level=levels.remove();
        wmes=smem_get_direct_augs_of_id(parent_sym,tc);
{
          for (          WmeImpl w_p : wmes) {
            if (((store_only) && ((parent_level != 0) || ((w_p.attr != predefinedSyms.smem_sym_query) && (w_p.attr != predefinedSyms.smem_sym_retrieve)))) || ((!store_only) && ((parent_level != 0) || (w_p.attr != predefinedSyms.smem_sym_store)))) {
              wme_count++;
              if (w_p.timetag > smem_info.last_cmd_time[time_slot]) {
                new_cue=true;
                smem_info.last_cmd_time[time_slot]=w_p.timetag;
              }
              if ((w_p.value.asIdentifier() != null) && (parent_level == 0) && ((w_p.attr == predefinedSyms.smem_sym_query) || (w_p.attr == predefinedSyms.smem_sym_store))) {
                syms.add(w_p.value.asIdentifier());
                levels.add(parent_level + 1);
              }
            }
          }
          if (cmds == null) {
            cmds=wmes;
          }
 else {
            wmes=null;
          }
        }
      }
      if (smem_info.last_cmd_count[time_slot] != wme_count) {
        new_cue=true;
        smem_info.last_cmd_count[time_slot]=wme_count;
      }
      if (new_cue) {
        smem_info.cue_wmes.clear();
        smem_clear_result(state);
        smem_made_changes=true;
      }
    }
    if (new_cue && wme_count != 0) {
      retrieve=null;
      query=null;
      store.clear();
      prohibit.clear();
      path=path_type.blank_slate;
      for (      WmeImpl w_p : cmds) {
        smem_info.cue_wmes.add(w_p);
        if (path != path_type.cmd_bad) {
          if (w_p.attr == predefinedSyms.smem_sym_retrieve) {
            if ((w_p.value.asIdentifier() != null) && (path == path_type.blank_slate)) {
              retrieve=w_p.value.asIdentifier();
              path=path_type.cmd_retrieve;
            }
 else {
              path=path_type.cmd_bad;
            }
          }
 else           if (w_p.attr == predefinedSyms.smem_sym_query) {
            if ((w_p.value.asIdentifier() != null) && ((path == path_type.blank_slate) || (path == path_type.cmd_query)) && (query == null)) {
              query=w_p.value.asIdentifier();
              path=path_type.cmd_query;
            }
 else {
              path=path_type.cmd_bad;
            }
          }
 else           if (w_p.attr == predefinedSyms.smem_sym_prohibit) {
            if ((w_p.value.asIdentifier() != null) && ((path == path_type.blank_slate) || (path == path_type.cmd_query)) && (w_p.value.asIdentifier().smem_lti != 0)) {
              prohibit.add(w_p.value.asIdentifier());
              path=path_type.cmd_query;
            }
 else {
              path=path_type.cmd_bad;
            }
          }
 else           if (w_p.attr == predefinedSyms.smem_sym_store) {
            if ((w_p.value.asIdentifier() != null) && ((path == path_type.blank_slate) || (path == path_type.cmd_store))) {
              store.add(w_p.value.asIdentifier());
              path=path_type.cmd_store;
            }
 else {
              path=path_type.cmd_bad;
            }
          }
 else {
            path=path_type.cmd_bad;
          }
        }
      }
      if ((path == path_type.cmd_query) && (query == null)) {
        path=path_type.cmd_bad;
      }
      if (path == path_type.blank_slate) {
        path=path_type.cmd_bad;
      }
      if (path != path_type.cmd_bad) {
        smem_attach();
        if (path == path_type.cmd_retrieve) {
          if (retrieve.smem_lti == 0) {
            smem_add_meta_wme(state,smem_info.smem_result_header,predefinedSyms.smem_sym_failure,retrieve);
          }
 else {
            smem_add_meta_wme(state,smem_info.smem_result_header,predefinedSyms.smem_sym_success,retrieve);
            smem_install_memory(state,retrieve.smem_lti,retrieve);
          }
        }
 else         if (path == path_type.cmd_query) {
          final Set<Long> prohibit_lti=new HashSet<Long>();
          for (          IdentifierImpl sym_p : prohibit) {
            prohibit_lti.add(sym_p.smem_lti);
          }
          smem_process_query(state,query,prohibit_lti);
        }
 else         if (path == path_type.cmd_store) {
          if (!params.lazy_commit.get()) {
            db.begin.executeUpdate();
          }
          for (          IdentifierImpl sym_p : store) {
            smem_soar_store(sym_p);
            smem_add_meta_wme(state,smem_info.smem_result_header,predefinedSyms.smem_sym_success,sym_p);
          }
          if (!params.lazy_commit.get()) {
            db.commit.executeUpdate();
          }
        }
      }
 else {
        smem_add_meta_wme(state,smem_info.smem_result_header,predefinedSyms.smem_sym_bad_cmd,smem_info.smem_cmd_header);
      }
    }
 else {
    }
    cmds=null;
    state=state.higher_goal;
  }
}