Program: 13148
Project: 13148
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override public Promise<QueryResponse,ResourceException> queryCollection(final Context context,final QueryRequest request,final QueryResourceHandler handler){
  try {
    if (request.getQueryExpression() != null) {
      return new BadRequestException(HttpUtils.PARAM_QUERY_EXPRESSION + "String_Node_Str").asPromise();
    }
    final QueryRequest queryRequest=Requests.newQueryRequest(REPO_RESOURCE_PATH);
    final boolean queryAllIds=ServerConstants.QUERY_ALL_IDS.equals(request.getQueryId());
    if (request.getQueryId() != null) {
      request.setQueryFilter(QueryFilter.<JsonPointer>alwaysTrue());
      if (ServerConstants.QUERY_ALL_IDS.equals(request.getQueryId())) {
        request.addField(FIELD_ID);
      }
 else       if (!"String_Node_Str".equals(request.getQueryId())) {
        return new BadRequestException("String_Node_Str" + HttpUtils.PARAM_QUERY_ID + "String_Node_Str").asPromise();
      }
    }
    queryRequest.setQueryFilter(request.getQueryFilter());
    queryRequest.setPageSize(request.getPageSize());
    queryRequest.setPagedResultsOffset(request.getPagedResultsOffset());
    queryRequest.setPagedResultsCookie(request.getPagedResultsCookie());
    queryRequest.setTotalPagedResultsPolicy(request.getTotalPagedResultsPolicy());
    queryRequest.addSortKey(request.getSortKeys().toArray(new SortKey[request.getSortKeys().size()]));
    for (    String key : request.getAdditionalParameters().keySet()) {
      queryRequest.setAdditionalParameter(key,request.getAdditionalParameter(key));
    }
    QueryFilter<JsonPointer> filter;
    ResourcePath resourcePath=firstResourcePath(context,request);
    if (isRevereseRelationship) {
      QueryFilter<JsonPointer> firstFilter=and(equalTo(new JsonPointer(REPO_FIELD_FIRST_ID),resourcePath),equalTo(new JsonPointer(REPO_FIELD_FIRST_PROPERTY_NAME),propertyName));
      QueryFilter<JsonPointer> secondFilter=and(equalTo(new JsonPointer(REPO_FIELD_SECOND_ID),resourcePath),equalTo(new JsonPointer(REPO_FIELD_SECOND_PROPERTY_NAME),propertyName));
      if (request.getQueryFilter() != null) {
        filter=or(and(firstFilter,and(firstFilter,asRelationshipQueryFilter(false,request.getQueryFilter()))),and(secondFilter,and(secondFilter,asRelationshipQueryFilter(true,request.getQueryFilter()))));
      }
 else {
        filter=or(firstFilter,secondFilter);
      }
    }
 else {
      filter=and(equalTo(new JsonPointer(REPO_FIELD_FIRST_ID),resourcePath),equalTo(new JsonPointer(REPO_FIELD_FIRST_PROPERTY_NAME),propertyName));
      if (request.getQueryFilter() != null) {
        filter=and(filter,asRelationshipQueryFilter(isRevereseRelationship,request.getQueryFilter()));
      }
    }
    queryRequest.setQueryFilter(filter);
    final Promise<QueryResponse,ResourceException> response=getConnection().queryAsync(context,queryRequest,new QueryResourceHandler(){
      @Override public boolean handleResource(      ResourceResponse resource){
        ResourceResponse filteredResourceResponse=formatResponseNoException(context,request).apply(resource);
        if (queryAllIds) {
          filteredResourceResponse.addField(FIELD_ID);
          return handler.handleResource(filteredResourceResponse);
        }
        try {
          filteredResourceResponse=expandFields(context,request,filteredResourceResponse).getOrThrow();
        }
 catch (        Exception e) {
          logger.error("String_Node_Str" + e.getMessage(),e);
        }
        return handler.handleResource(filteredResourceResponse);
      }
    }
);
    if (context.containsContext(ManagedObjectContext.class)) {
      return response;
    }
    QueryResponse result=response.getOrThrow();
    final ResourceResponse value=getManagedObject(context);
    activityLogger.log(context,request,"String_Node_Str",getManagedObjectPath(context),null,value.getContent(),Status.SUCCESS);
    return newResultPromise(result);
  }
 catch (  ResourceException e) {
    return e.asPromise();
  }
catch (  Exception e) {
    return new InternalServerErrorException(e.getMessage(),e).asPromise();
  }
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override public Promise<QueryResponse,ResourceException> queryCollection(final Context context,final QueryRequest request,final QueryResourceHandler handler){
  try {
    if (request.getQueryExpression() != null) {
      return new BadRequestException(HttpUtils.PARAM_QUERY_EXPRESSION + "String_Node_Str").asPromise();
    }
    final QueryRequest queryRequest=Requests.newQueryRequest(REPO_RESOURCE_PATH);
    final boolean queryAllIds=ServerConstants.QUERY_ALL_IDS.equals(request.getQueryId());
    if (request.getQueryId() != null) {
      request.setQueryFilter(QueryFilter.<JsonPointer>alwaysTrue());
      if (ServerConstants.QUERY_ALL_IDS.equals(request.getQueryId())) {
        request.addField(FIELD_ID);
      }
 else       if (!"String_Node_Str".equals(request.getQueryId())) {
        return new BadRequestException("String_Node_Str" + HttpUtils.PARAM_QUERY_ID + "String_Node_Str").asPromise();
      }
    }
    queryRequest.setQueryFilter(request.getQueryFilter());
    queryRequest.setPageSize(request.getPageSize());
    queryRequest.setPagedResultsOffset(request.getPagedResultsOffset());
    queryRequest.setPagedResultsCookie(request.getPagedResultsCookie());
    queryRequest.setTotalPagedResultsPolicy(request.getTotalPagedResultsPolicy());
    queryRequest.addSortKey(request.getSortKeys().toArray(new SortKey[request.getSortKeys().size()]));
    for (    String key : request.getAdditionalParameters().keySet()) {
      queryRequest.setAdditionalParameter(key,request.getAdditionalParameter(key));
    }
    QueryFilter<JsonPointer> filter;
    ResourcePath resourcePath=firstResourcePath(context,request);
    if (isReverseRelationship) {
      QueryFilter<JsonPointer> firstFilter=and(equalTo(new JsonPointer(REPO_FIELD_FIRST_ID),resourcePath),equalTo(new JsonPointer(REPO_FIELD_FIRST_PROPERTY_NAME),propertyName));
      QueryFilter<JsonPointer> secondFilter=and(equalTo(new JsonPointer(REPO_FIELD_SECOND_ID),resourcePath),equalTo(new JsonPointer(REPO_FIELD_SECOND_PROPERTY_NAME),propertyName));
      if (request.getQueryFilter() != null) {
        filter=or(and(firstFilter,and(firstFilter,asRelationshipQueryFilter(false,request.getQueryFilter()))),and(secondFilter,and(secondFilter,asRelationshipQueryFilter(true,request.getQueryFilter()))));
      }
 else {
        filter=or(firstFilter,secondFilter);
      }
    }
 else {
      filter=and(equalTo(new JsonPointer(REPO_FIELD_FIRST_ID),resourcePath),equalTo(new JsonPointer(REPO_FIELD_FIRST_PROPERTY_NAME),propertyName));
      if (request.getQueryFilter() != null) {
        filter=and(filter,asRelationshipQueryFilter(isReverseRelationship,request.getQueryFilter()));
      }
    }
    queryRequest.setQueryFilter(filter);
    final Promise<QueryResponse,ResourceException> response=getConnection().queryAsync(context,queryRequest,new QueryResourceHandler(){
      @Override public boolean handleResource(      ResourceResponse resource){
        ResourceResponse filteredResourceResponse=formatResponseNoException(context,request).apply(resource);
        if (queryAllIds) {
          filteredResourceResponse.addField(FIELD_ID);
          return handler.handleResource(filteredResourceResponse);
        }
        try {
          filteredResourceResponse=expandFields(context,request,filteredResourceResponse).getOrThrow();
        }
 catch (        Exception e) {
          logger.error("String_Node_Str" + e.getMessage(),e);
        }
        return handler.handleResource(filteredResourceResponse);
      }
    }
);
    if (context.containsContext(ManagedObjectContext.class)) {
      return response;
    }
    QueryResponse result=response.getOrThrow();
    final ResourceResponse value=getManagedObject(context);
    activityLogger.log(context,request,"String_Node_Str",getManagedObjectPath(context),null,value.getContent(),Status.SUCCESS);
    return newResultPromise(result);
  }
 catch (  ResourceException e) {
    return e.asPromise();
  }
catch (  Exception e) {
    return new InternalServerErrorException(e.getMessage(),e).asPromise();
  }
}