Program: 13249
Project: 13249
Buggy source:
@Override public void queryCollection(final ServerContext context,final QueryRequest request,final QueryResultHandler handler){
  EventEntry measure=null;
  try {
    final ConnectorFacade facade=getConnectorFacade0(handler,SearchApiOp.class);
    if (null == facade) {
      return;
    }
    OperationOptionsBuilder operationOptionsBuilder=operations.get(SearchApiOp.class).build(jsonConfiguration,objectClassInfoHelper);
    Filter filter=null;
    if (request.getQueryId() != null) {
      if (ServerConstants.QUERY_ALL_IDS.equals(request.getQueryId())) {
        operationOptionsBuilder.setAttributesToGet(Uid.NAME);
      }
 else {
        handler.handleError(new BadRequestException("String_Node_Str" + request.getQueryId()));
        return;
      }
    }
 else     if (request.getQueryExpression() != null) {
      filter=QueryFilter.valueOf(request.getQueryExpression()).accept(RESOURCE_FILTER,objectClassInfoHelper);
    }
 else {
      filter=request.getQueryFilter().accept(RESOURCE_FILTER,objectClassInfoHelper);
    }
    final int pageSize=request.getPageSize();
    final String pagedResultsCookie=request.getPagedResultsCookie();
    final boolean pagedResultsRequested=request.getPageSize() > 0;
    if (pageSize > 0) {
      operationOptionsBuilder.setPageSize(pageSize);
    }
    if (null != pagedResultsCookie) {
      operationOptionsBuilder.setPagedResultsCookie(pagedResultsCookie);
    }
    operationOptionsBuilder.setPagedResultsOffset(request.getPagedResultsOffset());
    if (null != request.getSortKeys()) {
      List<SortKey> sortKeys=new ArrayList<SortKey>(request.getSortKeys().size());
      for (      org.forgerock.json.resource.SortKey s : request.getSortKeys()) {
        sortKeys.add(new SortKey(s.getField().leaf(),s.isAscendingOrder()));
      }
      operationOptionsBuilder.setSortKeys(sortKeys);
    }
    SearchResult searchResult=facade.search(objectClassInfoHelper.getObjectClass(),filter,new ResultsHandler(){
      @Override public boolean handle(      ConnectorObject obj){
        try {
          return handler.handleResource(objectClassInfoHelper.build(obj,cryptoService));
        }
 catch (        Exception e) {
          handler.handleError(new InternalServerErrorException(e));
          return false;
        }
      }
    }
,operationOptionsBuilder.build());
    handler.handleResult(new QueryResult(searchResult != null ? searchResult.getPagedResultsCookie() : null,searchResult != null ? searchResult.getRemainingPagedResults() : -1));
  }
 catch (  ResourceException e) {
    handler.handleError(e);
  }
catch (  ConnectorException e) {
    handleConnectorException(context,request,e,null,null,null,handler,activityLogger);
  }
catch (  JsonValueException e) {
    handler.handleError(new BadRequestException(e));
  }
catch (  Exception e) {
    handler.handleError(new InternalServerErrorException(e));
  }
 finally {
  }
}

Fixed version (ground truth):
@Override public void queryCollection(final ServerContext context,final QueryRequest request,final QueryResultHandler handler){
  EventEntry measure=null;
  try {
    final ConnectorFacade facade=getConnectorFacade0(handler,SearchApiOp.class);
    if (null == facade) {
      return;
    }
    OperationOptionsBuilder operationOptionsBuilder=operations.get(SearchApiOp.class).build(jsonConfiguration,objectClassInfoHelper);
    Filter filter=null;
    if (request.getQueryId() != null) {
      if (ServerConstants.QUERY_ALL_IDS.equals(request.getQueryId())) {
        operationOptionsBuilder.setAttributesToGet(Uid.NAME);
      }
 else {
        handler.handleError(new BadRequestException("String_Node_Str" + request.getQueryId()));
        return;
      }
    }
 else     if (request.getQueryExpression() != null) {
      filter=QueryFilter.valueOf(request.getQueryExpression()).accept(RESOURCE_FILTER,objectClassInfoHelper);
    }
 else {
      filter=request.getQueryFilter().accept(RESOURCE_FILTER,objectClassInfoHelper);
    }
    final int pageSize=request.getPageSize();
    final String pagedResultsCookie=request.getPagedResultsCookie();
    final boolean pagedResultsRequested=request.getPageSize() > 0;
    if (pageSize > 0) {
      operationOptionsBuilder.setPageSize(pageSize);
    }
    if (null != pagedResultsCookie) {
      operationOptionsBuilder.setPagedResultsCookie(pagedResultsCookie);
    }
    operationOptionsBuilder.setPagedResultsOffset(request.getPagedResultsOffset());
    if (null != request.getSortKeys()) {
      List<SortKey> sortKeys=new ArrayList<SortKey>(request.getSortKeys().size());
      for (      org.forgerock.json.resource.SortKey s : request.getSortKeys()) {
        sortKeys.add(new SortKey(s.getField().leaf(),s.isAscendingOrder()));
      }
      operationOptionsBuilder.setSortKeys(sortKeys);
    }
    SearchResult searchResult=facade.search(objectClassInfoHelper.getObjectClass(),filter,new ResultsHandler(){
      @Override public boolean handle(      ConnectorObject obj){
        try {
          return handler.handleResource(objectClassInfoHelper.build(obj,cryptoService));
        }
 catch (        Exception e) {
          handler.handleError(new InternalServerErrorException(e.getMessage(),e));
          return false;
        }
      }
    }
,operationOptionsBuilder.build());
    handler.handleResult(new QueryResult(searchResult != null ? searchResult.getPagedResultsCookie() : null,searchResult != null ? searchResult.getRemainingPagedResults() : -1));
  }
 catch (  ResourceException e) {
    handler.handleError(e);
  }
catch (  ConnectorException e) {
    handleConnectorException(context,request,e,null,null,null,handler,activityLogger);
  }
catch (  JsonValueException e) {
    handler.handleError(new BadRequestException(e.getMessage(),e));
  }
catch (  Exception e) {
    handler.handleError(new InternalServerErrorException(e.getMessage(),e));
  }
 finally {
  }
}