Program: 105036
Project: 105036
Buggy source:
private List<Endpoint> speechActivityEndpointsChanged(List<Endpoint> endpoints,boolean pinnedEndpointChanged){
  Lock writeLock=lastNSyncRoot.writeLock();
  List<Endpoint> endpointsEnteringLastN=null;
  boolean lastNEndpointsChanged=pinnedEndpointChanged;
  writeLock.lock();
  try {
    int lastN=getLastN();
    if (endpoints == null) {
      endpoints=conferenceSpeechActivity.getEndpoints();
    }
    if (lastN >= 0) {
      Endpoint thisEndpoint=getEndpoint();
      endpointsEnteringLastN=new ArrayList<Endpoint>(lastN);
      for (      Endpoint e : endpoints) {
        if (endpointsEnteringLastN.size() >= lastN)         break;
        if (!e.equals(thisEndpoint))         endpointsEnteringLastN.add(e);
      }
      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);
        }
      }
      if (lastNEndpoints != null && !lastNEndpoints.isEmpty()) {
        int n=0;
        for (        WeakReference<Endpoint> wr : lastNEndpoints) {
          if (n >= lastN)           break;
          Endpoint e=wr.get();
          if (e != null) {
            if (e.equals(thisEndpoint)) {
              continue;
            }
 else {
              endpointsEnteringLastN.remove(e);
              if (lastNIndexOf(endpoints,lastN,e) < 0)               lastNEndpointsChanged=true;
            }
          }
          ++n;
        }
      }
    }
    lastNEndpoints=new ArrayList<WeakReference<Endpoint>>(endpoints.size());
    for (    Endpoint endpoint : endpoints)     lastNEndpoints.add(new WeakReference<Endpoint>(endpoint));
  }
  finally {
    writeLock.unlock();
  }
  if (endpointsEnteringLastN != null && !endpointsEnteringLastN.isEmpty()) {
    lastNEndpointsChanged=true;
  }
  if (lastNEndpointsChanged)   lastNEndpointsChanged(endpointsEnteringLastN);
  return endpointsEnteringLastN;
}

Fixed version (ground truth):
private List<Endpoint> speechActivityEndpointsChanged(List<Endpoint> endpoints,boolean pinnedEndpointChanged){
  Lock writeLock=lastNSyncRoot.writeLock();
  List<Endpoint> endpointsEnteringLastN=null;
  boolean lastNEndpointsChanged=pinnedEndpointChanged;
  writeLock.lock();
  try {
    int lastN=getLastN();
    if (endpoints == null) {
      endpoints=conferenceSpeechActivity.getEndpoints();
    }
    if (lastN >= 0) {
      Endpoint thisEndpoint=getEndpoint();
      endpointsEnteringLastN=new ArrayList<Endpoint>(lastN);
      Endpoint pinnedEndpoint=getPinnedEndpoint();
      if (pinnedEndpoint != null && lastN > 0) {
        endpointsEnteringLastN.add(pinnedEndpoint);
      }
      for (      Endpoint e : endpoints) {
        if (endpointsEnteringLastN.size() >= lastN)         break;
        if (!e.equals(thisEndpoint) && !e.equals(pinnedEndpoint))         endpointsEnteringLastN.add(e);
      }
      if (lastNEndpoints != null && !lastNEndpoints.isEmpty()) {
        int n=0;
        for (        WeakReference<Endpoint> wr : lastNEndpoints) {
          if (n >= lastN)           break;
          Endpoint e=wr.get();
          if (e != null) {
            if (e.equals(thisEndpoint)) {
              continue;
            }
 else {
              endpointsEnteringLastN.remove(e);
              if (lastNIndexOf(endpoints,lastN,e) < 0)               lastNEndpointsChanged=true;
            }
          }
          ++n;
        }
      }
    }
    lastNEndpoints=new ArrayList<WeakReference<Endpoint>>(endpoints.size());
    for (    Endpoint endpoint : endpoints)     lastNEndpoints.add(new WeakReference<Endpoint>(endpoint));
  }
  finally {
    writeLock.unlock();
  }
  if (endpointsEnteringLastN != null && !endpointsEnteringLastN.isEmpty()) {
    lastNEndpointsChanged=true;
  }
  if (lastNEndpointsChanged)   lastNEndpointsChanged(endpointsEnteringLastN);
  return endpointsEnteringLastN;
}