Program: 12178
Project: 12178
Buggy source:
/** 
 * <p>sml_KernelHelpers.cpp:906:soar_ecPrintPreferences <p>Parameters in original implementation are member properties here
 * @param agent The agent
 * @param printer The printer to print to
 * @throws IOException
 */
public void print(Agent agent,Printer printer) throws IOException {
  final PredefinedSymbols predefinedSyms=Adaptables.adapt(agent,PredefinedSymbols.class);
  if (object) {
    for (Slot s=id.slots; s != null; s=s.next) {
      if (s.attr == predefinedSyms.operator_symbol)       printer.print("String_Node_Str",s.id,s.attr);
 else       printer.print("String_Node_Str",s.id,s.attr);
      for (      PreferenceType pt : PreferenceType.values()) {
        if (s.getPreferencesByType(pt) != null) {
          if (s.isa_context_slot)           printer.print("String_Node_Str",pt.getDisplayName());
          for (Preference p=s.getPreferencesByType(pt); p != null; p=p.next) {
            print_preference_and_source(agent,printer,p);
          }
        }
      }
    }
    if (id.goalInfo != null && id.goalInfo.getImpasseWmes() != null)     printer.print("String_Node_Str",id);
    for (WmeImpl w=id.goalInfo != null ? id.goalInfo.getImpasseWmes() : null; w != null; w=w.next) {
      printer.print("String_Node_Str",w);
    }
    if (id.getInputWmes() != null)     printer.print("String_Node_Str",id);
    for (WmeImpl w=id.getInputWmes(); w != null; w=w.next) {
      printer.print("String_Node_Str",w);
    }
    return;
  }
 else   if (!id.isGoal() && attr == null) {
    for (    Wme w : agent.getAllWmesInRete()) {
      if (w.getValue() == id) {
        if (w.getValue() == predefinedSyms.operator_symbol)         printer.print("String_Node_Str");
 else         printer.print("String_Node_Str");
        printer.print("String_Node_Str",w.getTimetag(),w.getIdentifier(),w.getAttribute(),w.getValue());
        Iterator<Preference> it=w.getPreferences();
        if (!it.hasNext()) {
          printer.print("String_Node_Str");
        }
 else {
          while (it.hasNext()) {
            print_preference_and_source(agent,printer,it.next());
          }
        }
      }
    }
    return;
  }
  Slot s=Slot.find_slot(id,attr);
  if (s == null) {
    printer.print("String_Node_Str",id,attr);
    return;
  }
  printer.print("String_Node_Str",id,attr);
  for (  PreferenceType pt : PreferenceType.values()) {
    if (s.getPreferencesByType(pt) != null) {
      printer.print("String_Node_Str",pt.getDisplayName());
      for (Preference p=s.getPreferencesByType(pt); p != null; p=p.next) {
        print_preference_and_source(agent,printer,p);
      }
    }
  }
  if (id.isGoal() && attr.toString().equals("String_Node_Str")) {
    final ByRef<Preference> cand=ByRef.create(null);
    final Decider decider=Adaptables.adapt(agent,Decider.class);
    ImpasseType impasse_type=decider.run_preference_semantics(s,cand,true);
    if ((impasse_type == ImpasseType.NONE) && cand != null) {
      printer.print("String_Node_Str");
      int count=0;
      double total_probability=0;
      final Exploration exploration=Adaptables.adapt(agent,Exploration.class);
      for (Preference p=cand.value; p != null; p=p.next_candidate) {
        exploration.exploration_compute_value_of_candidate(p,s,0);
        ++count;
        if (p.numeric_value > 0)         total_probability+=p.numeric_value;
      }
      assert(count != 0);
      for (Preference p=cand.value; p != null; p=p.next_candidate) {
        double prob=total_probability > 0.0 ? p.numeric_value / total_probability : 1.0 / count;
        print_preference_and_source(agent,printer,p,prob);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * <p>sml_KernelHelpers.cpp:906:soar_ecPrintPreferences <p>Parameters in original implementation are member properties here
 * @param agent The agent
 * @param printer The printer to print to
 * @throws IOException
 */
public void print(Agent agent,Printer printer) throws IOException {
  final PredefinedSymbols predefinedSyms=Adaptables.adapt(agent,PredefinedSymbols.class);
  if (object) {
    for (Slot s=id.slots; s != null; s=s.next) {
      if (s.attr == predefinedSyms.operator_symbol)       printer.print("String_Node_Str",s.id,s.attr);
 else       printer.print("String_Node_Str",s.id,s.attr);
      for (      PreferenceType pt : PreferenceType.values()) {
        if (s.getPreferencesByType(pt) != null) {
          if (s.isa_context_slot)           printer.print("String_Node_Str",pt.getDisplayName());
          for (Preference p=s.getPreferencesByType(pt); p != null; p=p.next) {
            print_preference_and_source(agent,printer,p);
          }
        }
      }
    }
    if (id.goalInfo != null && id.goalInfo.getImpasseWmes() != null)     printer.print("String_Node_Str",id);
    for (WmeImpl w=id.goalInfo != null ? id.goalInfo.getImpasseWmes() : null; w != null; w=w.next) {
      printer.print("String_Node_Str",w);
    }
    if (id.getInputWmes() != null)     printer.print("String_Node_Str",id);
    for (WmeImpl w=id.getInputWmes(); w != null; w=w.next) {
      printer.print("String_Node_Str",w);
    }
    return;
  }
 else   if (!id.isGoal() && attr == null) {
    for (    Wme w : agent.getAllWmesInRete()) {
      if (w.getValue() == id) {
        if (w.getValue() == predefinedSyms.operator_symbol)         printer.print("String_Node_Str");
 else         printer.print("String_Node_Str");
        printer.print("String_Node_Str",w.getTimetag(),w.getIdentifier(),w.getAttribute(),w.getValue());
        Iterator<Preference> it=w.getPreferences();
        if (!it.hasNext()) {
          printer.print("String_Node_Str");
        }
 else {
          while (it.hasNext()) {
            print_preference_and_source(agent,printer,it.next());
          }
        }
      }
    }
    return;
  }
  Slot s=Slot.find_slot(id,attr);
  if (s == null) {
    printer.print("String_Node_Str",id,attr);
    return;
  }
  printer.print("String_Node_Str",id,attr);
  for (  PreferenceType pt : PreferenceType.values()) {
    if (s.getPreferencesByType(pt) != null) {
      printer.print("String_Node_Str",pt.getDisplayName());
      for (Preference p=s.getPreferencesByType(pt); p != null; p=p.next) {
        print_preference_and_source(agent,printer,p);
      }
    }
  }
  if (id.isGoal() && attr.toString().equals("String_Node_Str")) {
    final ByRef<Preference> cand=ByRef.create(null);
    final Decider decider=Adaptables.adapt(agent,Decider.class);
    ImpasseType impasse_type=decider.run_preference_semantics(s,cand,true);
    if ((impasse_type == ImpasseType.NONE) && cand.value != null) {
      printer.print("String_Node_Str");
      int count=0;
      double total_probability=0;
      final Exploration exploration=Adaptables.adapt(agent,Exploration.class);
      for (Preference p=cand.value; p != null; p=p.next_candidate) {
        exploration.exploration_compute_value_of_candidate(p,s,0);
        ++count;
        if (p.numeric_value > 0)         total_probability+=p.numeric_value;
      }
      assert(count != 0);
      for (Preference p=cand.value; p != null; p=p.next_candidate) {
        double prob=total_probability > 0.0 ? p.numeric_value / total_probability : 1.0 / count;
        print_preference_and_source(agent,printer,p,prob);
      }
    }
  }
}