Program: 12179
Project: 12179
Buggy source:
/** 
 * wma.cpp:920:wma_forgetting_update_p_queue
 * @return
 */
private boolean wma_forgetting_update_p_queue(){
  boolean return_val=false;
  boolean do_forget=false;
  if (!wma_forget_pq.isEmpty()) {
    final long current_cycle=wma_d_cycle_count;
    final double decay_thresh=wma_thresh_exp;
    final boolean forget_only_lti=(params.forget_wme.get() == ForgetWmeChoices.lti);
    final Map.Entry<Long,Set<wma_decay_element>> pq=wma_forget_pq.firstEntry();
    if (pq.getKey() == current_cycle) {
      for (      wma_decay_element current : pq.getValue()) {
        if (wma_calculate_decay_activation(current,current_cycle,false) < decay_thresh) {
          current.forget_cycle=WMA_FORGOTTEN_CYCLE;
          if (!forget_only_lti || ((IdentifierImpl)current.this_wme.getIdentifier()).smem_lti != 0) {
            do_forget=true;
            if (forget_only_lti) {
              for (Slot s=((IdentifierImpl)current.this_wme.getIdentifier()).slots; (s != null && do_forget); s=s.next) {
                for (WmeImpl w=s.getWmes(); (w != null && do_forget); w=w.next) {
                  final wma_decay_element wma_decay_el=wmaDecayElements.get(w);
                  if (w.preference.o_supported && (wma_decay_el == null || (wma_decay_el.forget_cycle != WMA_FORGOTTEN_CYCLE))) {
                    do_forget=false;
                  }
                }
              }
            }
            if (do_forget) {
              if (forget_only_lti) {
                for (Slot s=((IdentifierImpl)current.this_wme.getIdentifier()).slots; (s != null && do_forget); s=s.next) {
                  for (WmeImpl w=s.getWmes(); (w != null && do_forget); w=w.next) {
                    if (wma_forgetting_forget_wme(w)) {
                      return_val=true;
                    }
                  }
                }
              }
 else {
                if (wma_forgetting_forget_wme(current.this_wme)) {
                  return_val=true;
                }
              }
            }
          }
        }
 else {
          wma_forgetting_move_in_p_queue(current,wma_forgetting_estimate_cycle(current,false));
        }
      }
      wma_touched_sets.add(pq.getKey());
      pq.getValue().clear();
    }
    for (    long touched : wma_touched_sets) {
      final Set<wma_decay_element> pq_v=wma_forget_pq.get(touched);
      if (pq_v != null && pq_v.isEmpty()) {
        wma_forget_pq.remove(pq.getKey());
      }
    }
    wma_touched_sets.clear();
  }
  return return_val;
}

Fixed version (ground truth):
/** 
 * wma.cpp:920:wma_forgetting_update_p_queue
 * @return
 */
private boolean wma_forgetting_update_p_queue(){
  boolean return_val=false;
  boolean do_forget=false;
  if (!wma_forget_pq.isEmpty()) {
    final long current_cycle=wma_d_cycle_count;
    final double decay_thresh=wma_thresh_exp;
    final boolean forget_only_lti=(params.forget_wme.get() == ForgetWmeChoices.lti);
    final Map.Entry<Long,Set<wma_decay_element>> pq=wma_forget_pq.firstEntry();
    if (pq.getKey() == current_cycle) {
      for (      wma_decay_element current : pq.getValue()) {
        if (wma_calculate_decay_activation(current,current_cycle,false) < decay_thresh) {
          current.forget_cycle=WMA_FORGOTTEN_CYCLE;
          if (!forget_only_lti || ((IdentifierImpl)current.this_wme.getIdentifier()).smem_lti != 0) {
            do_forget=true;
            if (forget_only_lti) {
              for (Slot s=((IdentifierImpl)current.this_wme.getIdentifier()).slots; (s != null && do_forget); s=s.next) {
                for (WmeImpl w=s.getWmes(); (w != null && do_forget); w=w.next) {
                  final wma_decay_element wma_decay_el=wmaDecayElements.get(w);
                  if (w.preference.o_supported && (wma_decay_el == null || (wma_decay_el.forget_cycle != WMA_FORGOTTEN_CYCLE))) {
                    do_forget=false;
                  }
                }
              }
            }
            if (do_forget) {
              if (forget_only_lti) {
                for (Slot s=((IdentifierImpl)current.this_wme.getIdentifier()).slots; (s != null && do_forget); s=s.next) {
                  for (WmeImpl w=s.getWmes(); (w != null && do_forget); w=w.next) {
                    if (wma_forgetting_forget_wme(w)) {
                      return_val=true;
                    }
                  }
                }
              }
 else {
                if (wma_forgetting_forget_wme(current.this_wme)) {
                  return_val=true;
                }
              }
            }
          }
        }
 else {
          wma_forgetting_move_in_p_queue(current,wma_forgetting_estimate_cycle(current,false));
        }
      }
      wma_touched_sets.add(pq.getKey());
      pq.getValue().clear();
    }
    for (    long touched : wma_touched_sets) {
      final Set<wma_decay_element> pq_v=wma_forget_pq.get(touched);
      if (pq_v != null && pq_v.isEmpty()) {
        wma_forget_pq.remove(touched);
      }
    }
    wma_touched_sets.clear();
  }
  return return_val;
}