Program: 12224
Project: 12224
Buggy source:
/** 
 * <p>semantic_memory.cpp:1187:smem_store_chunk
 * @param parent_id
 * @param children
 * @param remove_old_children
 * @throws SQLException
 */
void smem_store_chunk(long parent_id,Map<SymbolImpl,List<smem_chunk_value>> children,boolean remove_old_children) throws SQLException {
  long attr_hash=0;
  long value_hash=0;
  long value_lti=0;
  Map<Long,Long> attr_ct_adjust=new HashMap<Long,Long>();
  Map<Long,Map<Long,Long>> const_ct_adjust=new HashMap<Long,Map<Long,Long>>();
  Map<Long,Map<Long,Long>> lti_ct_adjust=new HashMap<Long,Map<Long,Long>>();
  long stat_adjust=0;
  long next_act_cycle=smem_max_cycle++;
  long child_ct=0;
  if (remove_old_children) {
    smem_disconnect_chunk(parent_id);
  }
 else {
    db.act_lti_child_ct_get.setLong(1,parent_id);
    final ResultSet rs=db.act_lti_child_ct_get.executeQuery();
    try {
      child_ct=rs.getLong(0 + 1);
    }
  finally {
      rs.close();
    }
  }
  long thresh=0;
  boolean before_above=(child_ct >= thresh);
{
    for (    Map.Entry<SymbolImpl,List<smem_chunk_value>> s : children.entrySet()) {
      for (      smem_chunk_value v : s.getValue()) {
        child_ct++;
      }
    }
  }
  boolean after_above=(child_ct >= thresh);
  long web_act_cycle=((after_above) ? (SMEM_ACT_MAX) : (next_act_cycle));
  if ((!remove_old_children) && (!before_above)) {
    db.act_set.setLong(1,web_act_cycle);
    db.act_set.setLong(2,parent_id);
    db.act_set.executeUpdate();
  }
  if (after_above) {
    db.act_lti_set.setLong(1,next_act_cycle);
    db.act_lti_set.setLong(2,parent_id);
    db.act_lti_set.executeUpdate();
  }
  for (  Map.Entry<SymbolImpl,List<smem_chunk_value>> s : children.entrySet()) {
    attr_hash=smem_temporal_hash(s.getKey());
    final Long countForAttrHash=attr_ct_adjust.get(attr_hash);
    attr_ct_adjust.put(attr_hash,countForAttrHash != null ? countForAttrHash + 1 : 0 + 1);
    stat_adjust++;
    for (    smem_chunk_value v : s.getValue()) {
      final SymbolImpl constant=v.asConstant();
      if (constant != null) {
        value_hash=smem_temporal_hash(constant);
        db.web_add.setLong(1,parent_id);
        db.web_add.setLong(2,attr_hash);
        db.web_add.setLong(3,value_hash);
        db.web_add.setNull(4,java.sql.Types.NULL);
        db.web_add.setLong(5,web_act_cycle);
        db.web_add.executeUpdate();
        Map<Long,Long> forHash=const_ct_adjust.get(attr_hash);
        if (forHash == null) {
          forHash=new HashMap<Long,Long>();
          const_ct_adjust.put(attr_hash,forHash);
        }
        final Long countForValueHash=forHash.get(value_hash);
        forHash.put(value_hash,countForValueHash != null ? countForValueHash + 1 : 0 + 1);
      }
 else {
        value_lti=v.asLti().lti_id;
        if (value_lti == 0) {
          value_lti=smem_lti_add_id(v.asLti().lti_letter,v.asLti().lti_number);
          v.asLti().lti_id=value_lti;
          if (v.asLti().soar_id != null) {
            v.asLti().soar_id.smem_lti=value_lti;
          }
        }
        db.web_add.setLong(1,parent_id);
        db.web_add.setLong(2,attr_hash);
        db.web_add.setNull(3,java.sql.Types.NULL);
        db.web_add.setLong(4,value_lti);
        db.web_add.setLong(5,web_act_cycle);
        db.web_add.executeUpdate();
        Map<Long,Long> forHash=lti_ct_adjust.get(attr_hash);
        if (forHash == null) {
          forHash=new HashMap<Long,Long>();
          lti_ct_adjust.put(attr_hash,forHash);
        }
        final Long countForValueHash=forHash.get(value_lti);
        forHash.put(value_lti,countForValueHash != null ? countForValueHash + 1 : 0 + 1);
      }
    }
  }
{
  }
{
    for (    Map.Entry<Long,Long> p : attr_ct_adjust.entrySet()) {
      db.ct_attr_add.setLong(1,p.getKey());
      db.ct_attr_add.executeUpdate();
      db.ct_attr_update.setLong(1,p.getValue());
      db.ct_attr_update.setLong(2,p.getKey());
      db.ct_attr_update.executeUpdate();
    }
  }
{
    for (    Map.Entry<Long,Map<Long,Long>> p1 : const_ct_adjust.entrySet()) {
      for (      Map.Entry<Long,Long> p2 : p1.getValue().entrySet()) {
        db.ct_const_add.setLong(1,p1.getKey());
        db.ct_const_add.setLong(2,p2.getKey());
        db.ct_const_add.executeUpdate();
        db.ct_const_update.setLong(1,p2.getValue());
        db.ct_const_update.setLong(2,p1.getKey());
        db.ct_const_update.setLong(3,p2.getKey());
        db.ct_const_update.executeUpdate();
      }
    }
  }
{
    for (    Map.Entry<Long,Map<Long,Long>> p1 : lti_ct_adjust.entrySet()) {
      for (      Map.Entry<Long,Long> p2 : p1.getValue().entrySet()) {
        db.ct_lti_add.setLong(1,p1.getKey());
        db.ct_lti_add.setLong(2,p2.getKey());
        db.ct_lti_add.executeUpdate();
        db.ct_lti_update.setLong(1,p2.getValue());
        db.ct_lti_update.setLong(2,p1.getKey());
        db.ct_lti_update.setLong(3,p2.getKey());
        db.ct_lti_update.executeUpdate();
      }
    }
  }
{
    db.act_lti_child_ct_set.setLong(1,child_ct);
    db.act_lti_child_ct_set.setLong(2,parent_id);
    db.act_lti_child_ct_set.executeUpdate();
  }
}

Fixed version (ground truth):
/** 
 * <p>semantic_memory.cpp:1187:smem_store_chunk
 * @param parent_id
 * @param children
 * @param remove_old_children
 * @throws SQLException
 */
void smem_store_chunk(long parent_id,Map<SymbolImpl,List<smem_chunk_value>> children,boolean remove_old_children) throws SQLException {
  long attr_hash=0;
  long value_hash=0;
  long value_lti=0;
  Map<Long,Long> attr_ct_adjust=new HashMap<Long,Long>();
  Map<Long,Map<Long,Long>> const_ct_adjust=new HashMap<Long,Map<Long,Long>>();
  Map<Long,Map<Long,Long>> lti_ct_adjust=new HashMap<Long,Map<Long,Long>>();
  long stat_adjust=0;
  long next_act_cycle=smem_max_cycle++;
  long child_ct=0;
  if (remove_old_children) {
    smem_disconnect_chunk(parent_id);
  }
 else {
    db.act_lti_child_ct_get.setLong(1,parent_id);
    final ResultSet rs=db.act_lti_child_ct_get.executeQuery();
    try {
      child_ct=rs.getLong(0 + 1);
    }
  finally {
      rs.close();
    }
  }
  long thresh=100;
  boolean before_above=(child_ct >= thresh);
{
    for (    Map.Entry<SymbolImpl,List<smem_chunk_value>> s : children.entrySet()) {
      for (      smem_chunk_value v : s.getValue()) {
        child_ct++;
      }
    }
  }
  boolean after_above=(child_ct >= thresh);
  long web_act_cycle=((after_above) ? (SMEM_ACT_MAX) : (next_act_cycle));
  if ((!remove_old_children) && (!before_above)) {
    db.act_set.setLong(1,web_act_cycle);
    db.act_set.setLong(2,parent_id);
    db.act_set.executeUpdate();
  }
  if (after_above) {
    db.act_lti_set.setLong(1,next_act_cycle);
    db.act_lti_set.setLong(2,parent_id);
    db.act_lti_set.executeUpdate();
  }
  for (  Map.Entry<SymbolImpl,List<smem_chunk_value>> s : children.entrySet()) {
    attr_hash=smem_temporal_hash(s.getKey());
    final Long countForAttrHash=attr_ct_adjust.get(attr_hash);
    attr_ct_adjust.put(attr_hash,countForAttrHash != null ? countForAttrHash + 1 : 0 + 1);
    stat_adjust++;
    for (    smem_chunk_value v : s.getValue()) {
      final SymbolImpl constant=v.asConstant();
      if (constant != null) {
        value_hash=smem_temporal_hash(constant);
        db.web_add.setLong(1,parent_id);
        db.web_add.setLong(2,attr_hash);
        db.web_add.setLong(3,value_hash);
        db.web_add.setNull(4,java.sql.Types.NULL);
        db.web_add.setLong(5,web_act_cycle);
        db.web_add.executeUpdate();
        Map<Long,Long> forHash=const_ct_adjust.get(attr_hash);
        if (forHash == null) {
          forHash=new HashMap<Long,Long>();
          const_ct_adjust.put(attr_hash,forHash);
        }
        final Long countForValueHash=forHash.get(value_hash);
        forHash.put(value_hash,countForValueHash != null ? countForValueHash + 1 : 0 + 1);
      }
 else {
        value_lti=v.asLti().lti_id;
        if (value_lti == 0) {
          value_lti=smem_lti_add_id(v.asLti().lti_letter,v.asLti().lti_number);
          v.asLti().lti_id=value_lti;
          if (v.asLti().soar_id != null) {
            v.asLti().soar_id.smem_lti=value_lti;
          }
        }
        db.web_add.setLong(1,parent_id);
        db.web_add.setLong(2,attr_hash);
        db.web_add.setNull(3,java.sql.Types.NULL);
        db.web_add.setLong(4,value_lti);
        db.web_add.setLong(5,web_act_cycle);
        db.web_add.executeUpdate();
        Map<Long,Long> forHash=lti_ct_adjust.get(attr_hash);
        if (forHash == null) {
          forHash=new HashMap<Long,Long>();
          lti_ct_adjust.put(attr_hash,forHash);
        }
        final Long countForValueHash=forHash.get(value_lti);
        forHash.put(value_lti,countForValueHash != null ? countForValueHash + 1 : 0 + 1);
      }
    }
  }
{
  }
{
    for (    Map.Entry<Long,Long> p : attr_ct_adjust.entrySet()) {
      db.ct_attr_add.setLong(1,p.getKey());
      db.ct_attr_add.executeUpdate();
      db.ct_attr_update.setLong(1,p.getValue());
      db.ct_attr_update.setLong(2,p.getKey());
      db.ct_attr_update.executeUpdate();
    }
  }
{
    for (    Map.Entry<Long,Map<Long,Long>> p1 : const_ct_adjust.entrySet()) {
      for (      Map.Entry<Long,Long> p2 : p1.getValue().entrySet()) {
        db.ct_const_add.setLong(1,p1.getKey());
        db.ct_const_add.setLong(2,p2.getKey());
        db.ct_const_add.executeUpdate();
        db.ct_const_update.setLong(1,p2.getValue());
        db.ct_const_update.setLong(2,p1.getKey());
        db.ct_const_update.setLong(3,p2.getKey());
        db.ct_const_update.executeUpdate();
      }
    }
  }
{
    for (    Map.Entry<Long,Map<Long,Long>> p1 : lti_ct_adjust.entrySet()) {
      for (      Map.Entry<Long,Long> p2 : p1.getValue().entrySet()) {
        db.ct_lti_add.setLong(1,p1.getKey());
        db.ct_lti_add.setLong(2,p2.getKey());
        db.ct_lti_add.executeUpdate();
        db.ct_lti_update.setLong(1,p2.getValue());
        db.ct_lti_update.setLong(2,p1.getKey());
        db.ct_lti_update.setLong(3,p2.getKey());
        db.ct_lti_update.executeUpdate();
      }
    }
  }
{
    db.act_lti_child_ct_set.setLong(1,child_ct);
    db.act_lti_child_ct_set.setLong(2,parent_id);
    db.act_lti_child_ct_set.executeUpdate();
  }
}