Program: 9141
Project: 9141
Buggy source:
private Promise<Collection<ResourceSetDescription>,ResourceException> getPolicies(final ServerContext context,QueryRequest policyQuery,final String resourceOwnerId,final Set<ResourceSetDescription> resourceSets,final boolean augmentWithPolicies,final ResourceSetWithPolicyQuery query){
  return policyService.queryPolicies(context,policyQuery).thenAsync(new AsyncFunction<Pair<QueryResult,Collection<UmaPolicy>>,Collection<ResourceSetDescription>,ResourceException>(){
    @Override public Promise<Collection<ResourceSetDescription>,ResourceException> apply(    final Pair<QueryResult,Collection<UmaPolicy>> result){
      final Set<ResourceSetDescription> filteredResourceSets=new HashSet<>();
      try {
        String realm=context.asContext(RealmContext.class).getResolvedRealm();
        Subject subject=createSubject(resourceOwnerId,realm);
        Evaluator evaluator=umaProviderSettingsFactory.get(realm).getPolicyEvaluator(subject);
        for (        UmaPolicy sharedPolicy : result.getSecond()) {
          String sharedResourceName=sharedPolicy.getResourceSet().getName();
          List<Entitlement> entitlements=evaluator.evaluate(realm,subject,sharedResourceName,null,false);
          if (!entitlements.isEmpty()) {
            resourceSets.add(sharedPolicy.getResourceSet());
          }
        }
        filteredResourceSets.addAll(query.getResourceSetQuery().accept(new QueryFilterVisitor<Set<ResourceSetDescription>,Set<ResourceSetDescription>,String>(){
          @Override public Set<ResourceSetDescription> visitAndFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          List<org.forgerock.util.query.QueryFilter<String>> list){
            for (            org.forgerock.util.query.QueryFilter<String> filter : list) {
              resourceSetDescriptions.retainAll(filter.accept(this,resourceSetDescriptions));
            }
            return resourceSetDescriptions;
          }
          @Override public Set<ResourceSetDescription> visitBooleanLiteralFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          boolean value){
            if (value) {
              return resourceSetDescriptions;
            }
 else {
              return Collections.EMPTY_SET;
            }
          }
          @Override public Set<ResourceSetDescription> visitContainsFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String fieldName,          Object value){
            Set<ResourceSetDescription> results=new HashSet<>();
            for (            ResourceSetDescription resourceSetDescription : resourceSetDescriptions) {
              if (fieldName.equals("String_Node_Str")) {
                if (resourceSetDescription.getName().toLowerCase().contains(((String)value).toLowerCase())) {
                  results.add(resourceSetDescription);
                }
              }
            }
            return results;
          }
          @Override public Set<ResourceSetDescription> visitEqualsFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String fieldName,          Object value){
            Set<ResourceSetDescription> results=new HashSet<>();
            for (            ResourceSetDescription resourceSetDescription : resourceSetDescriptions) {
              if (fieldName.equals(ResourceSetTokenField.RESOURCE_OWNER_ID)) {
                if (resourceSetDescription.getResourceOwnerId().equals(value)) {
                  results.add(resourceSetDescription);
                }
              }
 else               if (fieldName.equals(ResourceSetTokenField.RESOURCE_SET_ID)) {
                if (resourceSetDescription.getId().equals(value)) {
                  results.add(resourceSetDescription);
                }
              }
            }
            return results;
          }
          @Override public Set<ResourceSetDescription> visitExtendedMatchFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          String s2,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitGreaterThanFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitGreaterThanOrEqualToFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitLessThanFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitLessThanOrEqualToFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitNotFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          org.forgerock.util.query.QueryFilter<String> queryFilter){
            Set<ResourceSetDescription> excludedResourceSets=queryFilter.accept(this,resourceSetDescriptions);
            resourceSetDescriptions.removeAll(excludedResourceSets);
            return resourceSetDescriptions;
          }
          @Override public Set<ResourceSetDescription> visitOrFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          List<org.forgerock.util.query.QueryFilter<String>> list){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitPresentFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitStartsWithFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
        }
,resourceSets));
        return Promises.newResultPromise((Collection<ResourceSetDescription>)filteredResourceSets);
      }
 catch (      EntitlementException e) {
        return Promises.newExceptionPromise((ResourceException)new InternalServerErrorException(e));
      }
    }
  }
);
}

Fixed version (ground truth):
private Promise<Collection<ResourceSetDescription>,ResourceException> getPolicies(final ServerContext context,QueryRequest policyQuery,final String resourceOwnerId,final Set<ResourceSetDescription> resourceSets,final boolean augmentWithPolicies,final ResourceSetWithPolicyQuery query){
  return policyService.queryPolicies(context,policyQuery).thenAsync(new AsyncFunction<Pair<QueryResult,Collection<UmaPolicy>>,Collection<ResourceSetDescription>,ResourceException>(){
    @Override public Promise<Collection<ResourceSetDescription>,ResourceException> apply(    final Pair<QueryResult,Collection<UmaPolicy>> result){
      final Set<ResourceSetDescription> filteredResourceSets=new HashSet<>();
      try {
        String realm=context.asContext(RealmContext.class).getResolvedRealm();
        Subject subject=createSubject(resourceOwnerId,realm);
        Evaluator evaluator=umaProviderSettingsFactory.get(realm).getPolicyEvaluator(subject);
        for (        UmaPolicy sharedPolicy : result.getSecond()) {
          if (!containsResourceSet(resourceSets,sharedPolicy.getResourceSet())) {
            String sharedResourceName=sharedPolicy.getResourceSet().getName();
            List<Entitlement> entitlements=evaluator.evaluate(realm,subject,sharedResourceName,null,false);
            if (!entitlements.isEmpty()) {
              resourceSets.add(sharedPolicy.getResourceSet());
            }
          }
        }
        filteredResourceSets.addAll(query.getResourceSetQuery().accept(new QueryFilterVisitor<Set<ResourceSetDescription>,Set<ResourceSetDescription>,String>(){
          @Override public Set<ResourceSetDescription> visitAndFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          List<org.forgerock.util.query.QueryFilter<String>> list){
            for (            org.forgerock.util.query.QueryFilter<String> filter : list) {
              resourceSetDescriptions.retainAll(filter.accept(this,resourceSetDescriptions));
            }
            return resourceSetDescriptions;
          }
          @Override public Set<ResourceSetDescription> visitBooleanLiteralFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          boolean value){
            if (value) {
              return resourceSetDescriptions;
            }
 else {
              return Collections.EMPTY_SET;
            }
          }
          @Override public Set<ResourceSetDescription> visitContainsFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String fieldName,          Object value){
            Set<ResourceSetDescription> results=new HashSet<>();
            for (            ResourceSetDescription resourceSetDescription : resourceSetDescriptions) {
              if (fieldName.equals("String_Node_Str")) {
                if (resourceSetDescription.getName().toLowerCase().contains(((String)value).toLowerCase())) {
                  results.add(resourceSetDescription);
                }
              }
            }
            return results;
          }
          @Override public Set<ResourceSetDescription> visitEqualsFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String fieldName,          Object value){
            Set<ResourceSetDescription> results=new HashSet<>();
            for (            ResourceSetDescription resourceSetDescription : resourceSetDescriptions) {
              if (fieldName.equals(ResourceSetTokenField.RESOURCE_OWNER_ID)) {
                if (resourceSetDescription.getResourceOwnerId().equals(value)) {
                  results.add(resourceSetDescription);
                }
              }
 else               if (fieldName.equals(ResourceSetTokenField.RESOURCE_SET_ID)) {
                if (resourceSetDescription.getId().equals(value)) {
                  results.add(resourceSetDescription);
                }
              }
            }
            return results;
          }
          @Override public Set<ResourceSetDescription> visitExtendedMatchFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          String s2,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitGreaterThanFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitGreaterThanOrEqualToFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitLessThanFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitLessThanOrEqualToFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitNotFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          org.forgerock.util.query.QueryFilter<String> queryFilter){
            Set<ResourceSetDescription> excludedResourceSets=queryFilter.accept(this,resourceSetDescriptions);
            resourceSetDescriptions.removeAll(excludedResourceSets);
            return resourceSetDescriptions;
          }
          @Override public Set<ResourceSetDescription> visitOrFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          List<org.forgerock.util.query.QueryFilter<String>> list){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitPresentFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s){
            throw new UnsupportedOperationException("String_Node_Str");
          }
          @Override public Set<ResourceSetDescription> visitStartsWithFilter(          Set<ResourceSetDescription> resourceSetDescriptions,          String s,          Object o){
            throw new UnsupportedOperationException("String_Node_Str");
          }
        }
,resourceSets));
        return Promises.newResultPromise((Collection<ResourceSetDescription>)filteredResourceSets);
      }
 catch (      EntitlementException e) {
        return Promises.newExceptionPromise((ResourceException)new InternalServerErrorException(e));
      }
    }
  }
);
}