Program: 35982
Project: 35982
Buggy source:
/** 
 * @param rsr
 * @param since
 * @param maxDurationSeconds. Zero for never, positive for fixed timeout, negative for fixed timeout or first update that needs publishing 
 * @throws IOException
 * @throws CoreException
 */
private void serveChangesFeed(RestServiceRequest rsr,long since,long maxDurationSeconds) throws IOException, CoreException {
  if (!rsr.request.isAsyncSupported())   throw new IllegalStateException("String_Node_Str");
  if (since < -1)   throw new IllegalArgumentException("String_Node_Str");
  if (rsr.request.getAttribute("String_Node_Str") == null) {
    if (RestServices.LOGPUBLISH.isDebugEnabled())     RestServices.LOGPUBLISH.debug("String_Node_Str" + rsr.request.getPathInfo());
    rsr.response.getOutputStream().write(RestServices.END_OF_HTTPHEADER.getBytes(RestServices.UTF8));
    if (since != -1) {
      boolean wroteSomeChanges=writeChanges(rsr,Core.createSystemContext(),since);
      if (wroteSomeChanges && maxDurationSeconds < 0) {
        rsr.endDoc();
        return;
      }
    }
    rsr.response.flushBuffer();
    AsyncContext asyncContext=rsr.request.startAsync();
synchronized (this) {
      ChangeFeedSubscriber lpsession=new ChangeFeedSubscriber(asyncContext,maxDurationSeconds < 0,this);
      longPollSessions.add(lpsession);
      rsr.request.setAttribute("String_Node_Str",lpsession);
    }
    if (maxDurationSeconds != 0L)     asyncContext.setTimeout(Math.abs(maxDurationSeconds) * 1000);
  }
 else {
    ChangeFeedSubscriber lpsession=(ChangeFeedSubscriber)rsr.request.getAttribute("String_Node_Str");
    unregisterListener(lpsession);
  }
}

Fixed version (ground truth):
/** 
 * @param rsr
 * @param since
 * @param maxDurationSeconds. Zero for never, positive for fixed timeout, negative for fixed timeout or first update that needs publishing 
 * @throws IOException
 * @throws CoreException
 */
private void serveChangesFeed(RestServiceRequest rsr,long since,long maxDurationSeconds) throws IOException, CoreException {
  if (!rsr.request.isAsyncSupported())   throw new IllegalStateException("String_Node_Str");
  if (since < -1)   throw new IllegalArgumentException("String_Node_Str");
  if (rsr.request.getAttribute("String_Node_Str") == null) {
    if (RestServices.LOGPUBLISH.isDebugEnabled())     RestServices.LOGPUBLISH.debug("String_Node_Str" + rsr.request.getPathInfo());
    rsr.response.getOutputStream().write(RestServices.END_OF_HTTPHEADER.getBytes(RestServices.UTF8));
    ObjectState lastWrittenChange=null;
    if (since != -1) {
      lastWrittenChange=writeChanges(rsr,Core.createSystemContext(),since);
      if (lastWrittenChange != null && maxDurationSeconds < 0) {
        rsr.endDoc();
        return;
      }
    }
    rsr.response.flushBuffer();
    AsyncContext asyncContext=rsr.request.startAsync();
synchronized (this) {
      if (since != -1)       writeChanges(rsr,Core.createSystemContext(),lastWrittenChange == null ? 0 : lastWrittenChange.getrevision());
      ChangeFeedSubscriber lpsession=new ChangeFeedSubscriber(asyncContext,maxDurationSeconds < 0,this);
      longPollSessions.add(lpsession);
      rsr.request.setAttribute("String_Node_Str",lpsession);
    }
    if (maxDurationSeconds != 0L)     asyncContext.setTimeout(Math.abs(maxDurationSeconds) * 1000);
  }
 else {
    ChangeFeedSubscriber lpsession=(ChangeFeedSubscriber)rsr.request.getAttribute("String_Node_Str");
    unregisterListener(lpsession);
  }
}