Program: 12278
Project: 12278
Buggy source:
/** 
 * This routine decides a given slot, which must be a non-context slot. It calls run_preference_semantics() on the slot, then updates the wmes and/or impasse for the slot accordingly. <p>decide.cpp:1510:decide_non_context_slot
 * @param s
 */
private void decide_non_context_slot(Slot s){
  final ByRef<Preference> candidates=ByRef.create(null);
  final ImpasseType impasse_type=run_preference_semantics(s,candidates,false,false);
  if (impasse_type == ImpasseType.NONE) {
    if (s.impasse_type != ImpasseType.NONE)     remove_existing_attribute_impasse_for_slot(s);
    for (WmeImpl w=s.getWmes(); w != null; w=w.next)     w.value.decider_flag=DeciderFlag.NOTHING;
    for (Preference cand=candidates.value; cand != null; cand=cand.next_candidate)     cand.value.decider_flag=DeciderFlag.CANDIDATE;
    WmeImpl it=s.getWmes();
    while (it != null) {
      final WmeImpl w=it;
      it=w.next;
      if (w.value.decider_flag == DeciderFlag.CANDIDATE) {
        w.value.decider_flag=DeciderFlag.ALREADY_EXISTING_WME;
        w.value.decider_wme=w;
      }
 else {
        s.removeWme(w);
        if (w.gds != null) {
          if (w.gds.getGoal() != null) {
            context.getTrace().print(EnumSet.of(Category.WM_CHANGES,Category.VERBOSE),"String_Node_Str",w.gds.getGoal().level,w);
            gds_invalid_so_remove_goal(w);
          }
        }
        this.workingMemory.remove_wme_from_wm(w);
      }
    }
    for (Preference cand=candidates.value; cand != null; cand=cand.next_candidate) {
      if (cand.value.decider_flag == DeciderFlag.ALREADY_EXISTING_WME) {
        cand.value.decider_wme.preference=cand;
      }
 else {
        WmeImpl w=this.workingMemory.make_wme(cand.id,cand.attr,cand.value,false);
        s.addWme(w);
        w.preference=cand;
        this.parent_list_head=null;
        if ((w.preference.o_supported == true) && (w.preference.inst.match_goal_level != 1)) {
          if (w.preference.inst.match_goal.gds == null) {
            if (w.preference.inst.match_goal_level == w.preference.id.level) {
              create_gds_for_goal(w.preference.inst.match_goal);
            }
 else {
              throw new IllegalStateException("String_Node_Str");
            }
          }
          for (Preference pref=w.preference; pref != null; pref=pref.next) {
            if (DEBUG_GDS_HIGH) {
              context.getPrinter().print("String_Node_Str",pref,pref.id.level);
            }
            if (pref.inst.GDS_evaluated_already == false) {
              if (DEBUG_GDS_HIGH) {
                context.getPrinter().print("String_Node_Str",pref.inst.prod.getName(),pref.inst.match_goal_level);
              }
              if (pref.inst.match_goal_level > pref.id.level) {
                if (DEBUG_GDS_HIGH) {
                  context.getPrinter().print("String_Node_Str",pref.inst.prod.getName());
                }
              }
 else {
                if (DEBUG_GDS_HIGH) {
                  context.getPrinter().print("String_Node_Str",pref.inst.prod.getName());
                }
                uniquely_add_to_head_of_dll(pref.inst);
                pref.inst.GDS_evaluated_already=true;
              }
            }
 else             if (DEBUG_GDS_HIGH) {
              context.getPrinter().print("String_Node_Str",pref.inst.prod.getName());
            }
          }
          if (DEBUG_GDS_HIGH) {
            context.getPrinter().print("String_Node_Str");
          }
          elaborate_gds();
          free_parent_list();
          if (DEBUG_GDS_HIGH) {
            context.getPrinter().print("String_Node_Str");
          }
        }
        this.workingMemory.add_wme_to_wm(w);
      }
    }
    return;
  }
  if (s.getWmes() != null) {
    this.workingMemory.remove_wme_list_from_wm(s.getWmes(),false);
    s.removeAllWmes();
  }
  if (s.impasse_type != ImpasseType.NONE) {
    if (s.impasse_type != impasse_type) {
      remove_existing_attribute_impasse_for_slot(s);
      create_new_attribute_impasse_for_slot(s,impasse_type);
    }
    update_impasse_items(s.impasse_id,candidates.value);
  }
 else {
    create_new_attribute_impasse_for_slot(s,impasse_type);
    update_impasse_items(s.impasse_id,candidates.value);
  }
}

Fixed version (ground truth):
/** 
 * This routine decides a given slot, which must be a non-context slot. It calls run_preference_semantics() on the slot, then updates the wmes and/or impasse for the slot accordingly. <p>decide.cpp:1510:decide_non_context_slot
 * @param s
 */
private void decide_non_context_slot(Slot s){
  final ByRef<Preference> candidates=ByRef.create(null);
  final ImpasseType impasse_type=run_preference_semantics(s,candidates,false,false);
  if (impasse_type == ImpasseType.NONE) {
    if (s.impasse_type != ImpasseType.NONE)     remove_existing_attribute_impasse_for_slot(s);
    for (WmeImpl w=s.getWmes(); w != null; w=w.next)     w.value.decider_flag=DeciderFlag.NOTHING;
    for (Preference cand=candidates.value; cand != null; cand=cand.next_candidate)     cand.value.decider_flag=DeciderFlag.CANDIDATE;
    WmeImpl it=s.getWmes();
    while (it != null) {
      final WmeImpl w=it;
      it=w.next;
      if (w.value.decider_flag == DeciderFlag.CANDIDATE) {
        w.value.decider_flag=DeciderFlag.ALREADY_EXISTING_WME;
        w.value.decider_wme=w;
      }
 else {
        s.removeWme(w);
        if (w.gds != null) {
          if (w.gds.getGoal() != null) {
            context.getTrace().print(EnumSet.of(Category.WM_CHANGES,Category.VERBOSE),"String_Node_Str",w.gds.getGoal().level,w);
            gds_invalid_so_remove_goal(w);
          }
        }
        this.workingMemory.remove_wme_from_wm(w);
      }
    }
    for (Preference cand=candidates.value; cand != null; cand=cand.next_candidate) {
      if (cand.value.decider_flag == DeciderFlag.ALREADY_EXISTING_WME) {
        cand.value.decider_wme.preference=cand;
      }
 else {
        WmeImpl w=this.workingMemory.make_wme(cand.id,cand.attr,cand.value,false);
        s.addWme(w);
        w.preference=cand;
        this.parent_list_head=null;
        if ((w.preference.o_supported == true) && (w.preference.inst.match_goal_level != 1)) {
          if (w.preference.inst.match_goal.gds == null) {
            if (w.preference.inst.match_goal_level == w.preference.id.level) {
              create_gds_for_goal(w.preference.inst.match_goal);
            }
 else {
              if (!this.decisionCycle.isHalted()) {
                throw new IllegalStateException("String_Node_Str");
              }
            }
          }
          if (this.decisionCycle.isHalted()) {
            for (Preference pref=w.preference; pref != null; pref=pref.next) {
              if (DEBUG_GDS_HIGH) {
                context.getPrinter().print("String_Node_Str",pref,pref.id.level);
              }
              if (pref.inst.GDS_evaluated_already == false) {
                if (DEBUG_GDS_HIGH) {
                  context.getPrinter().print("String_Node_Str",pref.inst.prod.getName(),pref.inst.match_goal_level);
                }
                if (pref.inst.match_goal_level > pref.id.level) {
                  if (DEBUG_GDS_HIGH) {
                    context.getPrinter().print("String_Node_Str",pref.inst.prod.getName());
                  }
                }
 else {
                  if (DEBUG_GDS_HIGH) {
                    context.getPrinter().print("String_Node_Str",pref.inst.prod.getName());
                  }
                  uniquely_add_to_head_of_dll(pref.inst);
                  pref.inst.GDS_evaluated_already=true;
                }
              }
 else               if (DEBUG_GDS_HIGH) {
                context.getPrinter().print("String_Node_Str",pref.inst.prod.getName());
              }
            }
            if (DEBUG_GDS_HIGH) {
              context.getPrinter().print("String_Node_Str");
            }
            elaborate_gds();
            free_parent_list();
            if (DEBUG_GDS_HIGH) {
              context.getPrinter().print("String_Node_Str");
            }
          }
        }
        this.workingMemory.add_wme_to_wm(w);
      }
    }
    return;
  }
  if (s.getWmes() != null) {
    this.workingMemory.remove_wme_list_from_wm(s.getWmes(),false);
    s.removeAllWmes();
  }
  if (s.impasse_type != ImpasseType.NONE) {
    if (s.impasse_type != impasse_type) {
      remove_existing_attribute_impasse_for_slot(s);
      create_new_attribute_impasse_for_slot(s,impasse_type);
    }
    update_impasse_items(s.impasse_id,candidates.value);
  }
 else {
    create_new_attribute_impasse_for_slot(s,impasse_type);
    update_impasse_items(s.impasse_id,candidates.value);
  }
}