Program: 12180
Project: 12180
Buggy source:
/** 
 * Add_preference_to_tm() adds a given preference to preference memory (and hence temporary memory).  <p>prefmem.cpp:216:add_preference_to_tm TODO I wish this was private, but smem and epmem use it.
 * @param pref
 */
public boolean add_preference_to_tm(Preference pref){
  Slot s=Slot.make_slot(pref.id,pref.attr,predefinedSyms.operator_symbol);
  if (!s.isa_context_slot && pref.o_supported && (pref.type == PreferenceType.ACCEPTABLE)&& (pref.inst.match_goal == this.decider.top_state)) {
    boolean already_top_o_supported=false;
    for (Preference p2=s.getAllPreferences(); (p2 != null && !already_top_o_supported); p2=p2.nextOfSlot) {
      if ((p2.value == pref.value) && p2.o_supported && (p2.inst.match_goal == this.decider.top_state)) {
        already_top_o_supported=true;
      }
    }
    if (already_top_o_supported) {
      return false;
    }
  }
  pref.slot=s;
  s.addPreference(pref);
  pref.preference_add_ref();
  if (wma.wma_enabled() && !s.isa_context_slot) {
    if (s.changed == null) {
      if (s.wma_val_references != null) {
        s.wma_val_references.clear();
      }
    }
  }
  tempMemory.mark_slot_as_changed(s);
  if (wma.wma_enabled() && !s.isa_context_slot) {
    boolean exists=false;
    WmeImpl w=pref.slot.getWmes();
    while (!exists && w != null) {
      if (w.getValue() == pref.value) {
        exists=true;
      }
      w=w.next;
    }
    if (!exists) {
      if (s.wma_val_references == null) {
        s.wma_val_references=new HashMap<Symbol,Long>();
      }
      Long numRef=s.wma_val_references.get(pref.value);
      if (numRef == null) {
        numRef=0L;
      }
      s.wma_val_references.put(pref.value,numRef);
    }
  }
  IdentifierImpl valueId=pref.value.asIdentifier();
  if (valueId != null) {
    decider.post_link_addition(pref.id,valueId);
  }
  if (pref.type.isBinary()) {
    IdentifierImpl refId=pref.referent.asIdentifier();
    if (refId != null) {
      decider.post_link_addition(pref.id,refId);
    }
  }
  if (s.isa_context_slot && (pref.type == PreferenceType.ACCEPTABLE || pref.type == PreferenceType.REQUIRE)) {
    decider.mark_context_slot_as_acceptable_preference_changed(s);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Add_preference_to_tm() adds a given preference to preference memory (and hence temporary memory).  <p>prefmem.cpp:216:add_preference_to_tm TODO I wish this was private, but smem and epmem use it.
 * @param pref
 */
public boolean add_preference_to_tm(Preference pref){
  Slot s=Slot.make_slot(pref.id,pref.attr,predefinedSyms.operator_symbol);
  if (!s.isa_context_slot && pref.o_supported && (pref.type == PreferenceType.ACCEPTABLE)&& (pref.inst.match_goal == this.decider.top_state)) {
    boolean already_top_o_supported=false;
    for (Preference p2=s.getAllPreferences(); (p2 != null && !already_top_o_supported); p2=p2.nextOfSlot) {
      if ((p2.value == pref.value) && p2.o_supported && (p2.inst.match_goal == this.decider.top_state)) {
        already_top_o_supported=true;
      }
    }
    if (already_top_o_supported) {
      return false;
    }
  }
  pref.slot=s;
  s.addPreference(pref);
  pref.preference_add_ref();
  if (wma.wma_enabled() && !s.isa_context_slot) {
    if (s.changed == null) {
      if (s.wma_val_references != null) {
        s.wma_val_references.clear();
      }
    }
  }
  tempMemory.mark_slot_as_changed(s);
  if (wma.wma_enabled() && !s.isa_context_slot) {
    boolean exists=false;
    WmeImpl w=pref.slot.getWmes();
    while (!exists && w != null) {
      if (w.getValue() == pref.value) {
        exists=true;
      }
      w=w.next;
    }
    if (!exists) {
      if (s.wma_val_references == null) {
        s.wma_val_references=new HashMap<Symbol,Long>();
      }
      Long numRef=s.wma_val_references.get(pref.value);
      if (numRef == null) {
        numRef=0L;
      }
      s.wma_val_references.put(pref.value,++numRef);
    }
  }
  IdentifierImpl valueId=pref.value.asIdentifier();
  if (valueId != null) {
    decider.post_link_addition(pref.id,valueId);
  }
  if (pref.type.isBinary()) {
    IdentifierImpl refId=pref.referent.asIdentifier();
    if (refId != null) {
      decider.post_link_addition(pref.id,refId);
    }
  }
  if (s.isa_context_slot && (pref.type == PreferenceType.ACCEPTABLE || pref.type == PreferenceType.REQUIRE)) {
    decider.mark_context_slot_as_acceptable_preference_changed(s);
  }
  return true;
}