Program: 35798
Project: 35798
Buggy source:
/** 
 * Selects the response to the request between a cache entry (if return code is 304) and the resource sent by the server (if return code is 200). Updates the cache.
 * @param resourceContext
 * @param cachedResponse
 * @param newResource
 * @return The response to send to the client
 * @throws HttpErrorPage
 */
public Resource select(ResourceContext resourceContext,CachedResponse cachedResponse,Resource newResource) throws HttpErrorPage {
  Resource result=null;
  if (newResource.getStatusCode() == HttpServletResponse.SC_NOT_MODIFIED) {
    String etag=Rfc2616.getEtag(newResource);
    if (etag == null) {
      String sentIfModifiedSince=getIfModifiedSince(resourceContext,cachedResponse);
      if (sentIfModifiedSince != null) {
        if (!resourceContext.isNeededForTransformation() && sentIfModifiedSince.equals(resourceContext.getOriginalRequest().getHeader("String_Node_Str")))         result=newResource;
 else         result=cachedResponse;
      }
    }
 else {
      if (!resourceContext.isNeededForTransformation() && Rfc2616.etagMatches(resourceContext,newResource))       result=newResource;
 else       result=findByEtag(etag);
    }
    if (cachedResponse != null)     updateHeaders(cachedResponse,newResource);
    if (result == null) {
      LOG.warn("String_Node_Str" + resourceContext.isNeededForTransformation() + "String_Node_Str"+ etag);
      throw new HttpErrorPage(HttpServletResponse.SC_PRECONDITION_FAILED,"String_Node_Str","String_Node_Str");
    }
  }
 else {
    result=newResource;
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Selects the response to the request between a cache entry (if return code is 304) and the resource sent by the server (if return code is 200). Updates the cache.
 * @param resourceContext
 * @param cachedResponse
 * @param newResource
 * @return The response to send to the client
 * @throws HttpErrorPage
 */
public Resource select(ResourceContext resourceContext,CachedResponse cachedResponse,Resource newResource) throws HttpErrorPage {
  Resource result=null;
  if (newResource.getStatusCode() == HttpServletResponse.SC_NOT_MODIFIED) {
    String etag=Rfc2616.getEtag(newResource);
    if (etag == null) {
      String sentIfModifiedSince=getIfModifiedSince(resourceContext,cachedResponse);
      if (sentIfModifiedSince != null) {
        if (!resourceContext.isNeededForTransformation() && sentIfModifiedSince.equals(resourceContext.getOriginalRequest().getHeader("String_Node_Str")))         result=newResource;
 else         result=cachedResponse;
      }
 else {
        if (cachedResponse != null)         result=cachedResponse;
 else         if (cachedResponses.size() > 0)         result=cachedResponses.values().iterator().next();
      }
    }
 else {
      if (!resourceContext.isNeededForTransformation() && Rfc2616.etagMatches(resourceContext,newResource))       result=newResource;
 else       result=findByEtag(etag);
    }
    if (cachedResponse != null)     updateHeaders(cachedResponse,newResource);
    if (result == null) {
      LOG.warn("String_Node_Str" + resourceContext.isNeededForTransformation() + "String_Node_Str"+ etag);
      throw new HttpErrorPage(HttpServletResponse.SC_PRECONDITION_FAILED,"String_Node_Str","String_Node_Str");
    }
  }
 else {
    result=newResource;
  }
  return result;
}