Program: 12280
Project: 12280
Buggy source:
/** 
 * <p>This routine is called once backtracing is finished. It goes through the ground conditions and builds a chunk_cond (see above) for each one. The chunk_cond includes two new copies of the condition: one to be used for the initial instantiation of the chunk, and one to be (variablized and) used for the chunk itself. <p>This routine also goes through the negated conditions and adds to the ground set (again building chunk_cond's) any negated conditions that are connected to the grounds. <p>At exit, the "dest_top" and "dest_bottom" arguments are set to point to the first and last chunk_cond in the ground set. The "tc_to_use" argument is the tc number that this routine will use to mark the TC of the ground set. At exit, this TC indicates the set of identifiers in the grounds. (This is used immediately afterwards to figure out which Nots must be added to the chunk.) <p>chunk.cpp:409:build_chunk_conds_for_grounds_and_add_negateds
 * @param dest_top
 * @param dest_bottom
 * @param tc_to_use
 */
private void build_chunk_conds_for_grounds_and_add_negateds(ByRef<ChunkCondition> dest_top,ByRef<ChunkCondition> dest_bottom,Marker tc_to_use){
  ListItem<ChunkCondition> first_cc=null;
  ListItem<ChunkCondition> prev_cc=null;
  while (!backtrace.grounds.isEmpty()) {
    Condition ground=backtrace.grounds.pop();
    ChunkCondition cc=new ChunkCondition(ground);
    cc.instantiated_cond=Condition.copy_condition(cc.cond);
    cc.variablized_cond=Condition.copy_condition(cc.cond);
    if (prev_cc != null) {
      prev_cc.next=cc.next_prev;
      cc.next_prev.previous=prev_cc;
      cc.variablized_cond.prev=prev_cc.item.variablized_cond;
      prev_cc.item.variablized_cond.next=cc.variablized_cond;
    }
 else {
      first_cc=cc.next_prev;
      cc.next_prev.previous=null;
      cc.variablized_cond.prev=null;
    }
    prev_cc=cc.next_prev;
    ground.add_cond_to_tc(tc_to_use,null,null);
  }
  final Trace trace=context.getTrace();
  trace.print(Category.BACKTRACING,"String_Node_Str");
  while (!negated_set.all.isEmpty()) {
    final ChunkCondition cc=negated_set.all.getFirstItem();
    negated_set.remove_from_chunk_cond_set(cc);
    if (cc.cond.cond_is_in_tc(tc_to_use)) {
      trace.print(Category.BACKTRACING,"String_Node_Str",cc.cond);
      cc.instantiated_cond=Condition.copy_condition(cc.cond);
      cc.variablized_cond=Condition.copy_condition(cc.cond);
      if (prev_cc != null) {
        prev_cc.next=cc.next_prev;
        cc.next_prev.previous=prev_cc;
        cc.variablized_cond.prev=prev_cc.item.variablized_cond;
        prev_cc.item.variablized_cond.next=cc.variablized_cond;
      }
 else {
        first_cc=cc.next_prev;
        cc.next_prev.previous=null;
        cc.variablized_cond.prev=null;
      }
      prev_cc=cc.next_prev;
    }
 else {
      if (!chunkThroughLocalNegations) {
        backtrace.report_local_negation(cc.cond);
        this.quiescence_t_flag=true;
        this.variablize_this_chunk=false;
      }
    }
  }
  if (prev_cc != null) {
    prev_cc.next=null;
    prev_cc.item.variablized_cond.next=null;
  }
 else {
    first_cc=null;
  }
  dest_top.value=first_cc.item;
  dest_bottom.value=prev_cc.item;
}

Fixed version (ground truth):
/** 
 * <p>This routine is called once backtracing is finished. It goes through the ground conditions and builds a chunk_cond (see above) for each one. The chunk_cond includes two new copies of the condition: one to be used for the initial instantiation of the chunk, and one to be (variablized and) used for the chunk itself. <p>This routine also goes through the negated conditions and adds to the ground set (again building chunk_cond's) any negated conditions that are connected to the grounds. <p>At exit, the "dest_top" and "dest_bottom" arguments are set to point to the first and last chunk_cond in the ground set. The "tc_to_use" argument is the tc number that this routine will use to mark the TC of the ground set. At exit, this TC indicates the set of identifiers in the grounds. (This is used immediately afterwards to figure out which Nots must be added to the chunk.) <p>chunk.cpp:409:build_chunk_conds_for_grounds_and_add_negateds
 * @param dest_top
 * @param dest_bottom
 * @param tc_to_use
 */
private void build_chunk_conds_for_grounds_and_add_negateds(ByRef<ChunkCondition> dest_top,ByRef<ChunkCondition> dest_bottom,Marker tc_to_use){
  ListItem<ChunkCondition> first_cc=null;
  ListItem<ChunkCondition> prev_cc=null;
  while (!backtrace.grounds.isEmpty()) {
    Condition ground=backtrace.grounds.pop();
    ChunkCondition cc=new ChunkCondition(ground);
    cc.instantiated_cond=Condition.copy_condition(cc.cond);
    cc.variablized_cond=Condition.copy_condition(cc.cond);
    if (prev_cc != null) {
      prev_cc.next=cc.next_prev;
      cc.next_prev.previous=prev_cc;
      cc.variablized_cond.prev=prev_cc.item.variablized_cond;
      prev_cc.item.variablized_cond.next=cc.variablized_cond;
      cc.instantiated_cond.prev=prev_cc.item.instantiated_cond;
      prev_cc.item.instantiated_cond.next=cc.instantiated_cond;
    }
 else {
      first_cc=cc.next_prev;
      cc.next_prev.previous=null;
      cc.variablized_cond.prev=null;
      cc.instantiated_cond.prev=null;
    }
    prev_cc=cc.next_prev;
    ground.add_cond_to_tc(tc_to_use,null,null);
  }
  final Trace trace=context.getTrace();
  trace.print(Category.BACKTRACING,"String_Node_Str");
  while (!negated_set.all.isEmpty()) {
    final ChunkCondition cc=negated_set.all.getFirstItem();
    negated_set.remove_from_chunk_cond_set(cc);
    if (cc.cond.cond_is_in_tc(tc_to_use)) {
      trace.print(Category.BACKTRACING,"String_Node_Str",cc.cond);
      cc.instantiated_cond=Condition.copy_condition(cc.cond);
      cc.variablized_cond=Condition.copy_condition(cc.cond);
      if (prev_cc != null) {
        prev_cc.next=cc.next_prev;
        cc.next_prev.previous=prev_cc;
        cc.variablized_cond.prev=prev_cc.item.variablized_cond;
        prev_cc.item.variablized_cond.next=cc.variablized_cond;
        cc.instantiated_cond.prev=prev_cc.item.instantiated_cond;
        prev_cc.item.instantiated_cond.next=cc.instantiated_cond;
      }
 else {
        first_cc=cc.next_prev;
        cc.next_prev.previous=null;
        cc.variablized_cond.prev=null;
        cc.instantiated_cond.prev=null;
      }
      prev_cc=cc.next_prev;
    }
 else {
      if (!chunkThroughLocalNegations) {
        backtrace.report_local_negation(cc.cond);
        this.quiescence_t_flag=true;
        this.variablize_this_chunk=false;
      }
    }
  }
  if (prev_cc != null) {
    prev_cc.next=null;
    prev_cc.item.variablized_cond.next=null;
    prev_cc.item.instantiated_cond.next=null;
  }
 else {
    first_cc=null;
  }
  dest_top.value=first_cc.item;
  dest_bottom.value=prev_cc.item;
}