Program: 105037
Project: 105037
Buggy source:
/** 
 * {@inheritDoc}
 */
@Override public void setLastN(Integer lastN){
  if (this.lastN == lastN)   return;
  boolean askForKeyframes=this.lastN == null;
  Lock writeLock=lastNSyncRoot.writeLock();
  List<Endpoint> endpointsEnteringLastN=new LinkedList<Endpoint>();
  writeLock.lock();
  try {
    if (this.lastN != null && this.lastN >= 0) {
      if (lastN > this.lastN) {
        int n=0;
        Endpoint thisEndpoint=getEndpoint();
        if (lastNEndpoints == null) {
          speechActivityEndpointsChanged(null);
        }
        if (lastNEndpoints != null) {
          for (          WeakReference<Endpoint> wr : lastNEndpoints) {
            if (n >= lastN)             break;
            Endpoint endpoint=wr.get();
            if (endpoint != null && endpoint.equals(thisEndpoint))             continue;
            ++n;
            if (n > this.lastN && endpoint != null)             endpointsEnteringLastN.add(endpoint);
          }
        }
        Endpoint pinnedEndpoint=getPinnedEndpoint();
        if (endpointsEnteringLastN.size() > 0 && pinnedEndpoint != null) {
          boolean found=false;
          for (          Endpoint e : endpointsEnteringLastN) {
            if (e != null) {
              if (pinnedEndpoint.getID().equals(e.getID())) {
                found=true;
                break;
              }
            }
          }
          if (!found) {
            endpointsEnteringLastN.remove(endpointsEnteringLastN.size() - 1);
            endpointsEnteringLastN.add(pinnedEndpoint);
          }
        }
      }
    }
    this.lastN=lastN;
  }
  finally {
    writeLock.unlock();
  }
  lastNEndpointsChanged(endpointsEnteringLastN);
  if (askForKeyframes) {
    getContent().askForKeyframes(new HashSet<Endpoint>(endpointsEnteringLastN));
  }
  touch();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc}
 */
@Override public void setLastN(Integer lastN){
  if (this.lastN == lastN)   return;
  boolean askForKeyframes=this.lastN == null;
  Lock writeLock=lastNSyncRoot.writeLock();
  List<Endpoint> endpointsEnteringLastN=new LinkedList<Endpoint>();
  writeLock.lock();
  try {
    if (this.lastN != null && this.lastN >= 0) {
      if (lastN > this.lastN) {
        Endpoint pinnedEndpoint=getPinnedEndpoint();
        int n=(pinnedEndpoint != null) ? 1 : 0;
        Endpoint thisEndpoint=getEndpoint();
        if (lastNEndpoints == null) {
          speechActivityEndpointsChanged(null);
        }
        if (lastNEndpoints != null) {
          for (          WeakReference<Endpoint> wr : lastNEndpoints) {
            if (n >= lastN)             break;
            Endpoint endpoint=wr.get();
            if (endpoint != null && (endpoint.equals(thisEndpoint) || endpoint.equals(pinnedEndpoint)))             continue;
            ++n;
            if (n > this.lastN && endpoint != null)             endpointsEnteringLastN.add(endpoint);
          }
        }
      }
    }
    this.lastN=lastN;
  }
  finally {
    writeLock.unlock();
  }
  lastNEndpointsChanged(endpointsEnteringLastN);
  if (askForKeyframes) {
    getContent().askForKeyframes(new HashSet<Endpoint>(endpointsEnteringLastN));
  }
  touch();
}