Program: 12202
Project: 12202
Buggy source:
/** 
 * This routine fills in a newly created instantiation structure with various information. <p>At input, the instantiation should have: <ul> <li>preferences_generated filled in;  <li>instantiated conditions filled in; <li>top-level positive conditions should have bt.wme_, bt.level, and bt.trace filled in, but bt.wme_ and bt.trace shouldn't have their reference counts incremented yet. </ul> This routine does the following: <ul> <li>increments reference count on production; <li>fills in match_goal and match_goal_level; <li>for each top-level positive cond: <ul> <li>replaces bt.trace with the preference for the correct level, <li>updates reference counts on bt.pref and bt.wmetraces and wmes </ul> <li>for each preference_generated, adds that pref to the list of all pref's for the match goal <li>fills in backtrace_number; <li>if "need_to_do_support_calculations" is TRUE, calculates o-support for preferences_generated; </ul> <p>recmem.cpp:385:fill_in_new_instantiation_stuff
 * @param inst
 * @param need_to_do_support_calculations
 * @param top_goal
 */
public void fill_in_new_instantiation_stuff(Instantiation inst,boolean need_to_do_support_calculations,final IdentifierImpl top_goal){
  find_match_goal(inst);
  int level=inst.match_goal_level;
  for (Condition cond=inst.top_of_instantiated_conditions; cond != null; cond=cond.next) {
    final PositiveCondition pc=cond.asPositiveCondition();
    if (pc != null) {
      if (SoarConstants.DO_TOP_LEVEL_REF_CTS) {
      }
 else {
        if (level > SoarConstants.TOP_GOAL_LEVEL) {
        }
      }
      final BackTraceInfo bt=pc.bt();
      if (bt.trace != null) {
        if (bt.trace.inst.match_goal_level > level) {
          bt.trace=Preference.find_clone_for_level(bt.trace,level);
        }
        if (bt.trace != null)         bt.trace.preference_add_ref();
      }
    }
  }
  if (inst.match_goal != null) {
    for (Preference p=inst.preferences_generated; p != null; p=p.inst_next) {
      inst.match_goal.goalInfo.addGoalPreference(p);
      p.on_goal_list=true;
    }
  }
  inst.backtrace_number=0;
  if (need_to_do_support_calculations) {
    osupport.calculate_support_for_instantiation_preferences(inst,top_goal);
  }
}

Fixed version (ground truth):
/** 
 * This routine fills in a newly created instantiation structure with various information. <p>At input, the instantiation should have: <ul> <li>preferences_generated filled in;  <li>instantiated conditions filled in; <li>top-level positive conditions should have bt.wme_, bt.level, and bt.trace filled in, but bt.wme_ and bt.trace shouldn't have their reference counts incremented yet. </ul> This routine does the following: <ul> <li>increments reference count on production; <li>fills in match_goal and match_goal_level; <li>for each top-level positive cond: <ul> <li>replaces bt.trace with the preference for the correct level, <li>updates reference counts on bt.pref and bt.wmetraces and wmes </ul> <li>for each preference_generated, adds that pref to the list of all pref's for the match goal <li>fills in backtrace_number; <li>if "need_to_do_support_calculations" is TRUE, calculates o-support for preferences_generated; </ul> <p>recmem.cpp:385:fill_in_new_instantiation_stuff
 * @param inst
 * @param need_to_do_support_calculations
 * @param top_goal
 */
public void fill_in_new_instantiation_stuff(Instantiation inst,boolean need_to_do_support_calculations,final IdentifierImpl top_goal){
  find_match_goal(inst);
  int level=inst.match_goal_level;
  for (Condition cond=inst.top_of_instantiated_conditions; cond != null; cond=cond.next) {
    final PositiveCondition pc=cond.asPositiveCondition();
    if (pc != null) {
      if (SoarConstants.DO_TOP_LEVEL_REF_CTS) {
      }
 else {
        if (level > SoarConstants.TOP_GOAL_LEVEL) {
        }
      }
      final BackTraceInfo bt=pc.bt();
      if (bt.trace != null) {
        if (bt.trace.inst.match_goal_level > level) {
          bt.trace=Preference.find_clone_for_level(bt.trace,level);
        }
        if (SoarConstants.DO_TOP_LEVEL_REF_CTS) {
          if (bt.trace != null)           bt.trace.preference_add_ref();
        }
 else {
          if ((bt.trace != null) && (level > SoarConstants.TOP_GOAL_LEVEL))           bt.trace.preference_add_ref();
        }
      }
    }
  }
  if (inst.match_goal != null) {
    for (Preference p=inst.preferences_generated; p != null; p=p.inst_next) {
      inst.match_goal.goalInfo.addGoalPreference(p);
      p.on_goal_list=true;
    }
  }
  inst.backtrace_number=0;
  if (need_to_do_support_calculations) {
    osupport.calculate_support_for_instantiation_preferences(inst,top_goal);
  }
}