Program: 12201
Project: 12201
Buggy source:
/** 
 * This routine scans through newly_created_instantiations, asserting each preference generated except for o-rejects. It also removes each instantiation from newly_created_instantiations, linking each onto the list of instantiations for that particular production. O-rejects are bufferred and handled after everything else. <p>Note that some instantiations on newly_created_instantiations are not in the match set--for the initial instantiations of chunks/justifications, if they don't match WM, we have to assert the o-supported preferences and throw away the rest. <p>recmem.cpp:891:assert_new_preferences
 */
private void assert_new_preferences(){
  final Trace trace=context.getTrace();
  final LinkedList<Preference> o_rejects=new LinkedList<Preference>();
  trace.print(Category.VERBOSE,"String_Node_Str");
  Instantiation inst, next_inst;
  for (inst=this.newly_created_instantiations; inst != null; inst=next_inst) {
    next_inst=inst.nextInProdList;
    Preference pref, next_pref;
    for (pref=inst.preferences_generated; pref != null; pref=next_pref) {
      next_pref=pref.inst_next;
      if ((pref.type == PreferenceType.REJECT) && (pref.o_supported)) {
        o_rejects.push(pref);
      }
    }
  }
  if (!o_rejects.isEmpty())   process_o_rejects_and_deallocate_them(o_rejects);
  for (inst=this.newly_created_instantiations; inst != null; inst=next_inst) {
    next_inst=inst.nextInProdList;
    if (inst.in_ms) {
      inst.prod.instantiations=inst.insertAtHeadOfProdList(inst.prod.instantiations);
    }
    trace.print(Category.VERBOSE,"String_Node_Str",inst.prod.getName());
    Preference pref, next_pref;
    for (pref=inst.preferences_generated; pref != null; pref=next_pref) {
      next_pref=pref.inst_next;
      if (inst.in_ms || pref.o_supported) {
        add_preference_to_tm(pref);
      }
 else {
        if (pref.next_clone != null)         pref.next_clone.prev_clone=pref.prev_clone;
        if (pref.prev_clone != null)         pref.prev_clone.next_clone=pref.next_clone;
        pref.next_clone=pref.prev_clone=null;
        pref.preference_add_ref();
        pref.preference_remove_ref(this);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * This routine scans through newly_created_instantiations, asserting each preference generated except for o-rejects. It also removes each instantiation from newly_created_instantiations, linking each onto the list of instantiations for that particular production. O-rejects are bufferred and handled after everything else. <p>Note that some instantiations on newly_created_instantiations are not in the match set--for the initial instantiations of chunks/justifications, if they don't match WM, we have to assert the o-supported preferences and throw away the rest. <p>recmem.cpp:891:assert_new_preferences
 * @bufdeallo Buffered preferences to deallocate after inner elaboration loop.
 */
private void assert_new_preferences(List<Preference> bufdeallo){
  final Trace trace=context.getTrace();
  final LinkedList<Preference> o_rejects=new LinkedList<Preference>();
  trace.print(Category.VERBOSE,"String_Node_Str");
  Instantiation inst, next_inst;
  for (inst=this.newly_created_instantiations; inst != null; inst=next_inst) {
    next_inst=inst.nextInProdList;
    Preference pref, next_pref;
    for (pref=inst.preferences_generated; pref != null; pref=next_pref) {
      next_pref=pref.inst_next;
      if ((pref.type == PreferenceType.REJECT) && (pref.o_supported)) {
        o_rejects.push(pref);
      }
    }
  }
  if (!o_rejects.isEmpty())   process_o_rejects_and_deallocate_them(o_rejects,bufdeallo);
  for (inst=this.newly_created_instantiations; inst != null; inst=next_inst) {
    next_inst=inst.nextInProdList;
    if (inst.in_ms) {
      inst.prod.instantiations=inst.insertAtHeadOfProdList(inst.prod.instantiations);
    }
    trace.print(Category.VERBOSE,"String_Node_Str",inst.prod.getName());
    Preference pref, next_pref;
    for (pref=inst.preferences_generated; pref != null; pref=next_pref) {
      next_pref=pref.inst_next;
      if (inst.in_ms || pref.o_supported) {
        add_preference_to_tm(pref);
      }
 else {
        if (pref.next_clone != null)         pref.next_clone.prev_clone=pref.prev_clone;
        if (pref.prev_clone != null)         pref.prev_clone.next_clone=pref.next_clone;
        pref.next_clone=pref.prev_clone=null;
        pref.preference_add_ref();
        pref.preference_remove_ref(this);
      }
    }
  }
}