Program: 12182
Project: 12182
Buggy source:
/** 
 * Add a preference to a slot's CDPS This function adds a preference to a slots's context dependent preference set, checking to first see whether the pref is already there. If an operator The slot's CDPS is copied to conditions' bt structs in create_instatiation. Those copies of the CDPS are used to backtrace through all relevant local evaluation rules that led to the selection of the operator that produced a result. decide.cpp:873:add_to_CDPS
 */
public void add_to_CDPS(Agent context,Preference pref,boolean unique_value){
  boolean already_exists=false;
  final Trace trace=context.getTrace();
  final Printer printer=trace.getPrinter();
  final boolean traceBacktracing=trace.isEnabled(Category.BACKTRACING);
  if (traceBacktracing) {
    printer.print("String_Node_Str",pref);
  }
  for (Iterator<Preference> it=this.CDPS.iterator(); it.hasNext(); ) {
    Preference p=it.next();
    if (p == pref) {
      already_exists=true;
      break;
    }
    if (unique_value) {
      if (((pref.type == PreferenceType.BETTER) || (pref.type == PreferenceType.WORSE)) && ((p.type == PreferenceType.BETTER) || (p.type == PreferenceType.WORSE))) {
        if (pref.type == p.type) {
          already_exists=((pref.value == p.value) && (pref.referent == p.referent));
        }
 else {
          already_exists=((pref.value == p.referent) && (pref.referent == p.value));
        }
      }
 else       if ((pref.type == PreferenceType.BINARY_INDIFFERENT) && (p.type == PreferenceType.BINARY_INDIFFERENT)) {
        already_exists=(((pref.value == p.value) && (pref.referent == p.referent)) || ((pref.value == p.referent) && (pref.referent == p.value)));
      }
 else {
        already_exists=(pref.value == p.value) && (pref.type == p.type);
      }
      if (already_exists) {
        break;
      }
    }
  }
  if (!already_exists) {
    this.CDPS.add(pref);
  }
 else   if (traceBacktracing) {
    printer.print("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Add a preference to a slot's CDPS This function adds a preference to a slots's context dependent preference set, checking to first see whether the pref is already there. If an operator The slot's CDPS is copied to conditions' bt structs in create_instatiation. Those copies of the CDPS are used to backtrace through all relevant local evaluation rules that led to the selection of the operator that produced a result. decide.cpp:873:add_to_CDPS
 */
public void add_to_CDPS(Agent context,Preference pref,boolean unique_value){
  boolean already_exists=false;
  final Trace trace=context.getTrace();
  final Printer printer=trace.getPrinter();
  final boolean traceBacktracing=trace.isEnabled(Category.BACKTRACING);
  if (traceBacktracing) {
    printer.print("String_Node_Str",pref);
  }
  if (this.CDPS == null) {
    this.CDPS=new LinkedList<Preference>();
  }
  for (Iterator<Preference> it=this.CDPS.iterator(); it.hasNext(); ) {
    Preference p=it.next();
    if (p == pref) {
      already_exists=true;
      break;
    }
    if (unique_value) {
      if (((pref.type == PreferenceType.BETTER) || (pref.type == PreferenceType.WORSE)) && ((p.type == PreferenceType.BETTER) || (p.type == PreferenceType.WORSE))) {
        if (pref.type == p.type) {
          already_exists=((pref.value == p.value) && (pref.referent == p.referent));
        }
 else {
          already_exists=((pref.value == p.referent) && (pref.referent == p.value));
        }
      }
 else       if ((pref.type == PreferenceType.BINARY_INDIFFERENT) && (p.type == PreferenceType.BINARY_INDIFFERENT)) {
        already_exists=(((pref.value == p.value) && (pref.referent == p.referent)) || ((pref.value == p.referent) && (pref.referent == p.value)));
      }
 else {
        already_exists=(pref.value == p.value) && (pref.type == p.type);
      }
      if (already_exists) {
        break;
      }
    }
  }
  if (!already_exists) {
    this.CDPS.push(pref);
    pref.preference_add_ref();
  }
 else   if (traceBacktracing) {
    printer.print("String_Node_Str");
  }
}