Program: 79674
Project: 79674
Buggy source:
/** 
 * <p>Creates or updates a resource set description.</p> <p>If the request contains a If-Match header an update is performed, otherwise a create is performed.</p> <p>An update will replace the current description of the resource set with the contents of the request body.</p>
 * @param entity The new resource set description.
 * @return A JSON object containing the authorization server's unique id for the resource set and, optionally,a policy uri.
 * @throws NotFoundException If the requested resource set description does not exist.
 * @throws ServerException When an error occurs during creating or updating.
 * @throws BadRequestException If the request JSON is invalid.
 */
@Post public Representation createResourceSet(JsonRepresentation entity) throws NotFoundException, ServerException, BadRequestException {
  ResourceSetDescription resourceSetDescription=new ResourceSetDescription(null,getClientId(),getResourceOwnerId(),validator.validate(toMap(entity)));
  OAuth2Request oAuth2Request=requestFactory.create(getRequest());
  ResourceSetStore store=providerSettingsFactory.get(oAuth2Request).getResourceSetStore();
  QueryFilter<String> query=QueryFilter.and(QueryFilter.equalTo(ResourceSetTokenField.NAME,resourceSetDescription.getName()),QueryFilter.equalTo(ResourceSetTokenField.CLIENT_ID,getClientId()),QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_OWNER_ID,getResourceOwnerId()));
  if (!store.query(query).isEmpty()) {
    getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
    Map<String,Object> response=new HashMap<String,Object>();
    response.put(OAuth2Constants.Params.ERROR,Status.CLIENT_ERROR_BAD_REQUEST.getReasonPhrase());
    response.put(OAuth2Constants.Params.ERROR_DESCRIPTION,"String_Node_Str" + resourceSetDescription.getName() + "String_Node_Str");
    return new JsonRepresentation(response);
  }
  JsonValue labels=resourceSetDescription.getDescription().get(OAuth2Constants.ResourceSets.LABELS);
  resourceSetDescription.getDescription().remove(OAuth2Constants.ResourceSets.LABELS);
  for (  ResourceRegistrationFilter filter : extensionFilterManager.getFilters(ResourceRegistrationFilter.class)) {
    filter.beforeResourceRegistration(resourceSetDescription);
  }
  store.create(oAuth2Request,resourceSetDescription);
  resourceSetDescription.getDescription().add(OAuth2Constants.ResourceSets.LABELS,labels);
  labelRegistration.updateLabelsForNewResourceSet(resourceSetDescription);
  for (  ResourceRegistrationFilter filter : extensionFilterManager.getFilters(ResourceRegistrationFilter.class)) {
    filter.afterResourceRegistration(resourceSetDescription);
  }
  for (  ResourceSetRegistrationListener listener : listeners) {
    listener.resourceSetCreated(oAuth2Request.<String>getParameter("String_Node_Str"),resourceSetDescription);
  }
  getResponse().setStatus(Status.SUCCESS_CREATED);
  return createJsonResponse(resourceSetDescription,false,true);
}

Fixed version (ground truth):
/** 
 * <p>Creates or updates a resource set description.</p> <p>If the request contains a If-Match header an update is performed, otherwise a create is performed.</p> <p>An update will replace the current description of the resource set with the contents of the request body.</p>
 * @param entity The new resource set description.
 * @return A JSON object containing the authorization server's unique id for the resource set and, optionally,a policy uri.
 * @throws NotFoundException If the requested resource set description does not exist.
 * @throws ServerException When an error occurs during creating or updating.
 * @throws BadRequestException If the request JSON is invalid.
 */
@Post public Representation createResourceSet(JsonRepresentation entity) throws NotFoundException, ServerException, BadRequestException {
  ResourceSetDescription resourceSetDescription=new ResourceSetDescription(null,getClientId(),getResourceOwnerId(),validator.validate(toMap(entity)));
  OAuth2Request oAuth2Request=requestFactory.create(getRequest());
  ResourceSetStore store=providerSettingsFactory.get(oAuth2Request).getResourceSetStore();
  QueryFilter<String> query=QueryFilter.and(QueryFilter.equalTo(ResourceSetTokenField.NAME,resourceSetDescription.getName()),QueryFilter.equalTo(ResourceSetTokenField.CLIENT_ID,getClientId()),QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_OWNER_ID,getResourceOwnerId()));
  if (!store.query(query).isEmpty()) {
    getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
    Map<String,Object> response=new HashMap<String,Object>();
    response.put(OAuth2Constants.Params.ERROR,Status.CLIENT_ERROR_BAD_REQUEST.getReasonPhrase());
    response.put(OAuth2Constants.Params.ERROR_DESCRIPTION,"String_Node_Str" + resourceSetDescription.getName() + "String_Node_Str");
    return new JsonRepresentation(response);
  }
  JsonValue labels=resourceSetDescription.getDescription().get(OAuth2Constants.ResourceSets.LABELS);
  resourceSetDescription.getDescription().remove(OAuth2Constants.ResourceSets.LABELS);
  for (  ResourceRegistrationFilter filter : extensionFilterManager.getFilters(ResourceRegistrationFilter.class)) {
    filter.beforeResourceRegistration(resourceSetDescription);
  }
  store.create(oAuth2Request,resourceSetDescription);
  if (labels.isNotNull()) {
    resourceSetDescription.getDescription().add(OAuth2Constants.ResourceSets.LABELS,labels.asSet());
  }
  labelRegistration.updateLabelsForNewResourceSet(resourceSetDescription);
  for (  ResourceRegistrationFilter filter : extensionFilterManager.getFilters(ResourceRegistrationFilter.class)) {
    filter.afterResourceRegistration(resourceSetDescription);
  }
  for (  ResourceSetRegistrationListener listener : listeners) {
    listener.resourceSetCreated(oAuth2Request.<String>getParameter("String_Node_Str"),resourceSetDescription);
  }
  getResponse().setStatus(Status.SUCCESS_CREATED);
  return createJsonResponse(resourceSetDescription,false,true);
}