Program: 8492
Project: 8492
Buggy source:
/** 
 * Invoke a custom query method on a repository and page the results based on URL parameters supplied by the user or the default page size.
 * @param request
 * @param pageSort
 * @param uriBuilder
 * @param repository
 * @param query
 * @return
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws IOException
 */
@SuppressWarnings({"String_Node_Str"}) @RequestMapping(value="String_Node_Str",method=RequestMethod.GET) @ResponseBody public ResponseEntity<?> query(ServletServerHttpRequest request,PagingAndSorting pageSort,UriComponentsBuilder uriBuilder,@PathVariable String repository,@PathVariable String query) throws InvocationTargetException, IllegalAccessException, IOException {
  URI baseUri=uriBuilder.build().toUri();
  RepositoryMetadata repoMeta=repositoryMetadataFor(repository);
  Repository repo=repoMeta.repository();
  RepositoryQueryMethod queryMethod=repoMeta.queryMethod(query);
  if (null == queryMethod) {
    return notFoundResponse(request);
  }
  Class<?>[] paramTypes=queryMethod.paramTypes();
  String[] paramNames=queryMethod.paramNames();
  Object[] paramVals=new Object[paramTypes.length];
  for (int i=0; i < paramVals.length; i++) {
    if (Pageable.class.isAssignableFrom(paramTypes[i])) {
      paramVals[i]=pageSort;
      continue;
    }
 else     if (Sort.class.isAssignableFrom(paramTypes[i])) {
      paramVals[i]=(null != pageSort ? pageSort.getSort() : null);
      continue;
    }
    String queryVal;
    if (null == (queryVal=request.getServletRequest().getParameter(paramNames[i]))) {
      continue;
    }
    RepositoryMetadata paramRepoMeta;
    if (String.class.isAssignableFrom(paramTypes[i])) {
      paramVals[i]=queryVal;
    }
 else     if (null != (paramRepoMeta=repositoryMetadataFor(paramTypes[i]))) {
      Serializable id=stringToSerializable(queryVal,(Class<Serializable>)paramRepoMeta.entityMetadata().idAttribute().type());
      Object o=paramRepoMeta.repository().findOne(id);
      if (null == o) {
        return notFoundResponse(request);
      }
      paramVals[i]=o;
    }
 else     if (conversionService.canConvert(String.class,paramTypes[i])) {
      paramVals[i]=conversionService.convert(queryVal,paramTypes[i]);
    }
 else {
      try {
        paramVals[i]=objectMapper.readValue(queryVal,paramTypes[i]);
      }
 catch (      IOException e) {
        throw new IllegalArgumentException(e);
      }
    }
  }
  RepositoryMethodResponse response=new RepositoryMethodResponse();
  Object result;
  if (null == (result=queryMethod.method().invoke(repo,paramVals))) {
    return negotiateResponse(request,HttpStatus.OK,new HttpHeaders(),response);
  }
  Iterator entities=Collections.emptyList().iterator();
  if (result instanceof Collection) {
    entities=((Collection)result).iterator();
    response.setTotalCount(((Collection)result).size());
  }
 else   if (result instanceof Page) {
    Page page=(Page)result;
    if (page.hasContent()) {
      entities=page.iterator();
    }
    response.setTotalCount(page.getTotalElements());
    response.setTotalPages(page.getTotalPages());
    response.setCurrentPage(page.getNumber() + 1);
    UriComponentsBuilder selfUri=UriComponentsBuilder.fromUri(baseUri).pathSegment(repository,"String_Node_Str",query);
    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",response.getLinks());
    maybeAddPrevNextLink(nextPrevBase,repoMeta,pageSort,page,!page.isLastPage() && page.hasNextPage(),page.getNumber() + 2,"String_Node_Str",response.getLinks());
  }
 else {
    entities=Collections.singletonList(result).iterator();
  }
  while (entities.hasNext()) {
    Object obj=entities.next();
    RepositoryMetadata elemRepoMeta;
    if (null == (elemRepoMeta=repositoryMetadataFor(obj.getClass()))) {
      response.addResult(obj);
      continue;
    }
    String id=elemRepoMeta.entityMetadata().idAttribute().get(obj).toString();
    if (shouldReturnLinks(request.getServletRequest().getHeader("String_Node_Str"))) {
      String rel=elemRepoMeta.rel() + "String_Node_Str" + elemRepoMeta.entityMetadata().type().getSimpleName();
      URI path=buildUri(baseUri,repository,id);
      response.addLink(new SimpleLink(rel,path));
    }
 else {
      Map<String,Object> entityDto=extractPropertiesLinkAware(repoMeta.rel(),obj,repoMeta.entityMetadata(),buildUri(baseUri,repository,id));
      addSelfLink(baseUri,entityDto,repository,id);
      response.addResult(entityDto);
    }
  }
  return negotiateResponse(request,HttpStatus.OK,new HttpHeaders(),response);
}

Fixed version (ground truth):
/** 
 * Invoke a custom query method on a repository and page the results based on URL parameters supplied by the user or the default page size.
 * @param request
 * @param pageSort
 * @param uriBuilder
 * @param repository
 * @param query
 * @return
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws IOException
 */
@SuppressWarnings({"String_Node_Str"}) @RequestMapping(value="String_Node_Str",method=RequestMethod.GET) @ResponseBody public ResponseEntity<?> query(ServletServerHttpRequest request,PagingAndSorting pageSort,UriComponentsBuilder uriBuilder,@PathVariable String repository,@PathVariable String query) throws InvocationTargetException, IllegalAccessException, IOException {
  URI baseUri=uriBuilder.build().toUri();
  RepositoryMetadata repoMeta=repositoryMetadataFor(repository);
  Repository repo=repoMeta.repository();
  RepositoryQueryMethod queryMethod=repoMeta.queryMethod(query);
  if (null == queryMethod) {
    return notFoundResponse(request);
  }
  Class<?>[] paramTypes=queryMethod.paramTypes();
  String[] paramNames=queryMethod.paramNames();
  Object[] paramVals=new Object[paramTypes.length];
  for (int i=0; i < paramVals.length; i++) {
    if (Pageable.class.isAssignableFrom(paramTypes[i])) {
      paramVals[i]=pageSort;
      continue;
    }
 else     if (Sort.class.isAssignableFrom(paramTypes[i])) {
      paramVals[i]=(null != pageSort ? pageSort.getSort() : null);
      continue;
    }
    String queryVal;
    if (null == (queryVal=request.getServletRequest().getParameter(paramNames[i]))) {
      continue;
    }
    if (String.class.isAssignableFrom(paramTypes[i])) {
      paramVals[i]=queryVal;
    }
 else     if (hasRepositoryMetadataFor(paramTypes[i])) {
      RepositoryMetadata paramRepoMeta=repositoryMetadataFor(paramTypes[i]);
      Serializable id=stringToSerializable(queryVal,(Class<Serializable>)paramRepoMeta.entityMetadata().idAttribute().type());
      Object o=paramRepoMeta.repository().findOne(id);
      if (null == o) {
        return notFoundResponse(request);
      }
      paramVals[i]=o;
    }
 else     if (conversionService.canConvert(String.class,paramTypes[i])) {
      paramVals[i]=conversionService.convert(queryVal,paramTypes[i]);
    }
 else {
      try {
        paramVals[i]=objectMapper.readValue(queryVal,paramTypes[i]);
      }
 catch (      IOException e) {
        throw new IllegalArgumentException(e);
      }
    }
  }
  RepositoryMethodResponse response=new RepositoryMethodResponse();
  Object result;
  if (null == (result=queryMethod.method().invoke(repo,paramVals))) {
    return negotiateResponse(request,HttpStatus.OK,new HttpHeaders(),response);
  }
  Iterator entities=Collections.emptyList().iterator();
  if (result instanceof Collection) {
    entities=((Collection)result).iterator();
    response.setTotalCount(((Collection)result).size());
  }
 else   if (result instanceof Page) {
    Page page=(Page)result;
    if (page.hasContent()) {
      entities=page.iterator();
    }
    response.setTotalCount(page.getTotalElements());
    response.setTotalPages(page.getTotalPages());
    response.setCurrentPage(page.getNumber() + 1);
    UriComponentsBuilder selfUri=UriComponentsBuilder.fromUri(baseUri).pathSegment(repository,"String_Node_Str",query);
    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",response.getLinks());
    maybeAddPrevNextLink(nextPrevBase,repoMeta,pageSort,page,!page.isLastPage() && page.hasNextPage(),page.getNumber() + 2,"String_Node_Str",response.getLinks());
  }
 else {
    entities=Collections.singletonList(result).iterator();
  }
  while (entities.hasNext()) {
    Object obj=entities.next();
    RepositoryMetadata elemRepoMeta;
    if (null == (elemRepoMeta=repositoryMetadataFor(obj.getClass()))) {
      response.addResult(obj);
      continue;
    }
    String id=elemRepoMeta.entityMetadata().idAttribute().get(obj).toString();
    if (shouldReturnLinks(request.getServletRequest().getHeader("String_Node_Str"))) {
      String rel=elemRepoMeta.rel() + "String_Node_Str" + elemRepoMeta.entityMetadata().type().getSimpleName();
      URI path=buildUri(baseUri,repository,id);
      response.addLink(new SimpleLink(rel,path));
    }
 else {
      Map<String,Object> entityDto=extractPropertiesLinkAware(repoMeta.rel(),obj,repoMeta.entityMetadata(),buildUri(baseUri,repository,id));
      addSelfLink(baseUri,entityDto,repository,id);
      response.addResult(entityDto);
    }
  }
  return negotiateResponse(request,HttpStatus.OK,new HttpHeaders(),response);
}