Program: 8499
Project: 8499
Buggy source:
/** 
 * List entities of a   {@link CrudRepository} by invoking{@link org.springframework.data.repository.CrudRepository#findAll()}and applying any available paging parameters.
 * @param request
 * @param pageSort
 * @param uriBuilder
 * @param repository
 * @return
 * @throws IOException
 */
@SuppressWarnings({"String_Node_Str"}) @RequestMapping(value="String_Node_Str",method=RequestMethod.GET) @ResponseBody public ResponseEntity<?> listEntities(ServletServerHttpRequest request,PagingAndSorting pageSort,UriComponentsBuilder uriBuilder,@PathVariable String repository) throws IOException {
  URI baseUri=uriBuilder.build().toUri();
  RepositoryMetadata repoMeta=repositoryMetadataFor(repository);
  if (!repoMeta.exportsMethod(CrudMethod.FIND_ALL)) {
    return negotiateResponse(request,HttpStatus.METHOD_NOT_ALLOWED,new HttpHeaders(),null);
  }
  Iterator allEntities=Collections.emptyList().iterator();
  final Resources resources;
  if (repoMeta.repository() instanceof PagingAndSortingRepository) {
    PageableResources pr=new PageableResources();
    Page page=((PagingAndSortingRepository)repoMeta.repository()).findAll(pageSort);
    if (page.hasContent()) {
      allEntities=page.iterator();
    }
    pr.setPaging(new PagingMetadata(page.getNumber() + 1,page.getTotalPages()));
    pr.setResourceCount(page.getTotalElements());
    UriComponentsBuilder selfUri=UriComponentsBuilder.fromUri(baseUri).pathSegment(repository);
    for (    String name : request.getServletRequest().getParameterMap().keySet()) {
      if (notPagingParam(name)) {
        selfUri.queryParam(name,request.getServletRequest().getParameter(name));
      }
    }
    URI nextPrevBase=selfUri.build().toUri();
    maybeAddPrevNextLink(nextPrevBase,repoMeta,pageSort,page,!page.isFirstPage() && page.hasPreviousPage(),page.getNumber(),"String_Node_Str",pr.getLinks());
    maybeAddPrevNextLink(nextPrevBase,repoMeta,pageSort,page,!page.isLastPage() && page.hasNextPage(),page.getNumber() + 2,"String_Node_Str",pr.getLinks());
    resources=pr;
  }
 else {
    Iterable it=repoMeta.repository().findAll();
    if (null != it) {
      allEntities=it.iterator();
    }
    resources=new Resources();
  }
  while (allEntities.hasNext()) {
    Object o=allEntities.next();
    Serializable id=(Serializable)repoMeta.entityMetadata().idAttribute().get(o);
    if (shouldReturnLinks(request.getServletRequest().getHeader("String_Node_Str"))) {
      resources.addLink(new SimpleLink(repoMeta.rel() + "String_Node_Str" + o.getClass().getSimpleName(),buildUri(baseUri,repository,id.toString())));
    }
 else {
      MapResource res=createResource(repoMeta.rel(),o,repoMeta.entityMetadata(),buildUri(baseUri,repository,id.toString()));
      URI selfUri=buildUri(baseUri,repository,id.toString());
      res.addLink(new SimpleLink(SELF,selfUri));
      resources.addResource(res);
    }
  }
  if (!repoMeta.queryMethods().isEmpty()) {
    resources.addLink(new SimpleLink(repoMeta.rel() + "String_Node_Str",buildUri(baseUri,repository,"String_Node_Str")));
  }
  publishEvent(new BeforeRenderResourcesEvent(request,repoMeta,resources));
  return negotiateResponse(request,HttpStatus.OK,new HttpHeaders(),resources);
}

Fixed version (ground truth):
/** 
 * List entities of a   {@link CrudRepository} by invoking{@link org.springframework.data.repository.CrudRepository#findAll()}and applying any available paging parameters.
 * @param request
 * @param pageSort
 * @param uriBuilder
 * @param repository
 * @return
 * @throws IOException
 */
@SuppressWarnings({"String_Node_Str"}) @RequestMapping(value="String_Node_Str",method=RequestMethod.GET) @ResponseBody public ResponseEntity<?> listEntities(ServletServerHttpRequest request,PagingAndSorting pageSort,UriComponentsBuilder uriBuilder,@PathVariable String repository) throws IOException {
  URI baseUri=uriBuilder.build().toUri();
  RepositoryMetadata repoMeta=repositoryMetadataFor(repository);
  if (!repoMeta.exportsMethod(CrudMethod.FIND_ALL)) {
    return negotiateResponse(request,HttpStatus.METHOD_NOT_ALLOWED,new HttpHeaders(),null);
  }
  Iterator allEntities=Collections.emptyList().iterator();
  final Resources resources;
  if (repoMeta.repository() instanceof PagingAndSortingRepository) {
    PageableResources pr=new PageableResources();
    Page page=((PagingAndSortingRepository)repoMeta.repository()).findAll(pageSort);
    if (page.hasContent()) {
      allEntities=page.iterator();
    }
    pr.setPaging(new PagingMetadata(page.getNumber() + 1,page.getTotalPages()));
    pr.setResourceCount(page.getTotalElements());
    UriComponentsBuilder selfUri=UriComponentsBuilder.fromUri(baseUri).pathSegment(repository);
    for (    String name : request.getServletRequest().getParameterMap().keySet()) {
      if (notPagingParam(name)) {
        selfUri.queryParam(name,request.getServletRequest().getParameter(name));
      }
    }
    URI nextPrevBase=selfUri.build().toUri();
    maybeAddPrevNextLink(nextPrevBase,repoMeta,pageSort,page,!page.isFirstPage() && page.hasPreviousPage(),page.getNumber(),"String_Node_Str",pr.getLinks());
    maybeAddPrevNextLink(nextPrevBase,repoMeta,pageSort,page,!page.isLastPage() && page.hasNextPage(),page.getNumber() + 2,"String_Node_Str",pr.getLinks());
    resources=pr;
  }
 else {
    Iterable it=repoMeta.repository().findAll();
    if (null != it) {
      allEntities=it.iterator();
    }
    resources=new Resources();
  }
  while (allEntities.hasNext()) {
    Object o=allEntities.next();
    Serializable id=(Serializable)repoMeta.entityMetadata().idAttribute().get(o);
    if (shouldReturnLinks(request.getServletRequest().getHeader("String_Node_Str"))) {
      resources.addLink(new SimpleLink(repoMeta.rel() + "String_Node_Str" + o.getClass().getSimpleName(),buildUri(baseUri,repository,id.toString())));
    }
 else {
      URI selfUri=buildUri(baseUri,repository,id.toString());
      MapResource res=createResource(repoMeta.rel(),o,repoMeta.entityMetadata(),selfUri);
      res.addLink(new SimpleLink(SELF,selfUri));
      resources.addResource(res);
    }
  }
  if (!repoMeta.queryMethods().isEmpty()) {
    resources.addLink(new SimpleLink(repoMeta.rel() + "String_Node_Str",buildUri(baseUri,repository,"String_Node_Str")));
  }
  publishEvent(new BeforeRenderResourcesEvent(request,repoMeta,resources));
  return negotiateResponse(request,HttpStatus.OK,new HttpHeaders(),resources);
}