Program: 12163
Project: 12163
Buggy source:
/** 
 * activates a new or existing long-term identifier note: optional num_edges parameter saves us a lookup just when storing a new chunk (default is a big number that should never come up naturally and if it does, satisfies thresholding behavior).
 * @param lti
 * @param add_access
 * @param num_edges
 * @throws SoarException 
 * @throws SQLException 
 */
double smem_lti_activate(long lti,boolean add_access,long num_edges) throws SQLException {
  long time_now;
  if (add_access) {
    time_now=this.smem_max_cycle++;
    if ((this.params.activation_mode.get() == DefaultSemanticMemoryParams.ActivationChoices.base) && (this.params.base_update.get() == DefaultSemanticMemoryParams.BaseUpdateChoices.incremental)) {
      long time_diff;
      for (Iterator<Long> b=this.params.base_incremental_threshes.get().iterator(); b.hasNext(); ) {
        Long next=b.next();
        if (next > 0) {
          time_diff=(time_now - next);
          if (time_diff > 0) {
            List<Long> to_update=new ArrayList<Long>();
            ResultSet rs=null;
            try {
              db.lti_get_t.setLong(1,time_diff);
              rs=db.lti_get_t.executeQuery();
              while (rs.next()) {
                to_update.add(rs.getLong(0 + 1));
              }
            }
  finally {
              rs.close();
            }
            for (            Long l : to_update) {
              smem_lti_activate(l,false);
            }
          }
        }
      }
    }
  }
 else {
    time_now=smem_max_cycle;
    this.stats.act_updates.set(this.stats.act_updates.get() + 1);
  }
  long prev_access_n=0;
  long prev_access_t=0;
  long prev_access_1=0;
{
    ResultSet rs=null;
    try {
      db.lti_access_get.setLong(1,lti);
      rs=db.lti_access_get.executeQuery();
      prev_access_n=rs.getLong(0 + 1);
      prev_access_t=rs.getLong(1 + 1);
      prev_access_1=rs.getLong(2 + 2);
    }
  finally {
      rs.close();
    }
    if (add_access) {
      db.lti_access_set.setLong(1,(prev_access_n + 1));
      db.lti_access_set.setLong(2,time_now);
      db.lti_access_set.setLong(3,((prev_access_n == 0) ? (time_now) : (prev_access_1)));
      db.lti_access_set.setLong(4,lti);
      db.lti_access_set.executeUpdate();
    }
  }
  double new_activation=0.0;
  ActivationChoices act_mode=this.params.activation_mode.get();
  if (act_mode == ActivationChoices.recency) {
    new_activation=time_now;
  }
 else   if (act_mode == ActivationChoices.frequency) {
    new_activation=prev_access_n + ((add_access) ? (1) : (0));
  }
 else   if (act_mode == ActivationChoices.base) {
    if (prev_access_n == 0) {
      if (add_access) {
        db.history_add.setLong(1,lti);
        db.history_add.setLong(2,time_now);
        db.history_add.executeUpdate();
      }
      new_activation=0;
    }
 else {
      if (add_access) {
        db.history_push.setLong(1,time_now);
        db.history_push.setLong(2,lti);
        db.history_push.executeUpdate();
      }
      new_activation=smem_lti_calc_base(lti,time_now + ((add_access) ? (1) : (0)),prev_access_n + ((add_access) ? (1) : (0)),prev_access_1);
    }
  }
  if (num_edges == SMEM_ACT_MAX) {
    ResultSet rs=null;
    try {
      db.act_lti_child_ct_get.setLong(1,lti);
      rs=db.act_lti_child_ct_get.executeQuery();
      num_edges=rs.getLong(0 + 1);
    }
  finally {
      rs.close();
    }
  }
  if (num_edges < this.params.thresh.get()) {
    db.act_set.setDouble(1,new_activation);
    db.act_set.setLong(2,lti);
    db.act_set.executeUpdate();
  }
{
    db.act_lti_set.setDouble(1,new_activation);
    db.act_lti_set.setLong(2,lti);
    db.act_lti_set.executeUpdate();
  }
  return new_activation;
}

Fixed version (ground truth):
/** 
 * activates a new or existing long-term identifier note: optional num_edges parameter saves us a lookup just when storing a new chunk (default is a big number that should never come up naturally and if it does, satisfies thresholding behavior).
 * @param lti
 * @param add_access
 * @param num_edges
 * @throws SoarException 
 * @throws SQLException 
 */
double smem_lti_activate(long lti,boolean add_access,long num_edges) throws SQLException {
  long time_now;
  if (add_access) {
    time_now=this.smem_max_cycle++;
    if ((this.params.activation_mode.get() == DefaultSemanticMemoryParams.ActivationChoices.base) && (this.params.base_update.get() == DefaultSemanticMemoryParams.BaseUpdateChoices.incremental)) {
      long time_diff;
      for (Iterator<Long> b=this.params.base_incremental_threshes.get().iterator(); b.hasNext(); ) {
        Long next=b.next();
        if (next > 0) {
          time_diff=(time_now - next);
          if (time_diff > 0) {
            List<Long> to_update=new ArrayList<Long>();
            ResultSet rs=null;
            try {
              db.lti_get_t.setLong(1,time_diff);
              rs=db.lti_get_t.executeQuery();
              while (rs.next()) {
                to_update.add(rs.getLong(0 + 1));
              }
            }
  finally {
              rs.close();
            }
            for (            Long l : to_update) {
              smem_lti_activate(l,false);
            }
          }
        }
      }
    }
  }
 else {
    time_now=smem_max_cycle;
    this.stats.act_updates.set(this.stats.act_updates.get() + 1);
  }
  long prev_access_n=0;
  long prev_access_t=0;
  long prev_access_1=0;
{
    ResultSet rs=null;
    try {
      db.lti_access_get.setLong(1,lti);
      rs=db.lti_access_get.executeQuery();
      prev_access_n=rs.getLong(0 + 1);
      prev_access_t=rs.getLong(1 + 1);
      prev_access_1=rs.getLong(2 + 1);
    }
  finally {
      rs.close();
    }
    if (add_access) {
      db.lti_access_set.setLong(1,(prev_access_n + 1));
      db.lti_access_set.setLong(2,time_now);
      db.lti_access_set.setLong(3,((prev_access_n == 0) ? (time_now) : (prev_access_1)));
      db.lti_access_set.setLong(4,lti);
      db.lti_access_set.executeUpdate();
    }
  }
  double new_activation=0.0;
  ActivationChoices act_mode=this.params.activation_mode.get();
  if (act_mode == ActivationChoices.recency) {
    new_activation=time_now;
  }
 else   if (act_mode == ActivationChoices.frequency) {
    new_activation=prev_access_n + ((add_access) ? (1) : (0));
  }
 else   if (act_mode == ActivationChoices.base) {
    if (prev_access_n == 0) {
      if (add_access) {
        db.history_add.setLong(1,lti);
        db.history_add.setLong(2,time_now);
        db.history_add.executeUpdate();
      }
      new_activation=0;
    }
 else {
      if (add_access) {
        db.history_push.setLong(1,time_now);
        db.history_push.setLong(2,lti);
        db.history_push.executeUpdate();
      }
      new_activation=smem_lti_calc_base(lti,time_now + ((add_access) ? (1) : (0)),prev_access_n + ((add_access) ? (1) : (0)),prev_access_1);
    }
  }
  if (num_edges == SMEM_ACT_MAX) {
    ResultSet rs=null;
    try {
      db.act_lti_child_ct_get.setLong(1,lti);
      rs=db.act_lti_child_ct_get.executeQuery();
      num_edges=rs.getLong(0 + 1);
    }
  finally {
      rs.close();
    }
  }
  if (num_edges < this.params.thresh.get()) {
    db.act_set.setDouble(1,new_activation);
    db.act_set.setLong(2,lti);
    db.act_set.executeUpdate();
  }
{
    db.act_lti_set.setDouble(1,new_activation);
    db.act_lti_set.setLong(2,lti);
    db.act_lti_set.executeUpdate();
  }
  return new_activation;
}