Program: 99398
Project: 99398
Buggy source:
@Override public ResourceDataResult filter(ResourceDataRequest request,FilterChain chain){
  if (request.getAction() == ResourceAction.DELETE) {
    return chain.filter(request);
  }
  Class clazz=request.getResourceClass();
  if (!ApiKey.class.isAssignableFrom(clazz) || ApiKeyList.class.isAssignableFrom(clazz)) {
    return chain.filter(request);
  }
  QueryString query=request.getUri().getQuery();
  boolean isQueryEmpty=Collections.isEmpty(query);
  boolean addEncryptionCriteria=isQueryEmpty || !query.containsKey(ENCRYPT_SECRET);
  boolean addEncryptionMetadata=addEncryptionCriteria || Boolean.parseBoolean(query.get(ENCRYPT_SECRET));
  if (addEncryptionCriteria) {
    DefaultApiKeyCriteria criteria=new DefaultApiKeyCriteria();
    criteria.add(new DefaultEqualsExpressionFactory(ENCRYPT_SECRET).eq(Boolean.TRUE));
    criteria.add(new DefaultEqualsExpressionFactory(ENCRYPTION_KEY_SIZE).eq(DEFAULT_ENCRYPTION_SIZE));
    criteria.add(new DefaultEqualsExpressionFactory(ENCRYPTION_KEY_ITERATIONS).eq(DEFAULT_ENCRYPTION_ITERATIONS));
    criteria.add(new DefaultEqualsExpressionFactory(ENCRYPTION_KEY_SALT).eq(saltGenerator.generate()));
    QueryString encryptionQueryParams=queryStringFactory.createQueryString(criteria);
    if (query == null) {
      CanonicalUri uri=new DefaultCanonicalUri(request.getUri().getAbsolutePath(),encryptionQueryParams);
      request=new DefaultResourceDataRequest(request.getAction(),uri,request.getResourceClass(),request.getData());
    }
 else {
      query.putAll(encryptionQueryParams);
    }
  }
  ResourceDataResult result=chain.filter(request);
  if (addEncryptionMetadata) {
    query=request.getUri().getQuery();
    Map<String,Object> encryptionMetadata=new LinkedHashMap<String,Object>();
    String salt=query.get(ENCRYPTION_KEY_SALT);
    Integer size=query.containsKey(ENCRYPTION_KEY_SIZE) ? Integer.valueOf(query.get(ENCRYPTION_KEY_SIZE)) : DEFAULT_ENCRYPTION_SIZE;
    Integer iterations=query.containsKey(ENCRYPTION_KEY_ITERATIONS) ? Integer.valueOf(query.get(ENCRYPTION_KEY_ITERATIONS)) : DEFAULT_ENCRYPTION_ITERATIONS;
    encryptionMetadata.put(ENCRYPTION_KEY_SALT,salt);
    encryptionMetadata.put(ENCRYPTION_KEY_SIZE,size);
    encryptionMetadata.put(ENCRYPTION_KEY_ITERATIONS,iterations);
    Map<String,Object> data=result.getData();
    data.put(ENCRYPTION_METADATA,encryptionMetadata);
  }
  return result;
}

Fixed version (ground truth):
@Override public ResourceDataResult filter(ResourceDataRequest request,FilterChain chain){
  if (request.getAction() == ResourceAction.DELETE) {
    return chain.filter(request);
  }
  Class clazz=request.getResourceClass();
  boolean isCollection=false;
  if (!(ApiKey.class.isAssignableFrom(clazz) || (isCollection=ApiKeyList.class.isAssignableFrom(clazz)))) {
    return chain.filter(request);
  }
  QueryString query=request.getUri().getQuery();
  boolean isQueryEmpty=Collections.isEmpty(query);
  boolean addEncryptionCriteria=isQueryEmpty || !query.containsKey(ENCRYPT_SECRET);
  boolean addEncryptionMetadata=addEncryptionCriteria || Boolean.parseBoolean(query.get(ENCRYPT_SECRET));
  if (addEncryptionCriteria) {
    DefaultApiKeyCriteria criteria=new DefaultApiKeyCriteria();
    criteria.add(new DefaultEqualsExpressionFactory(ENCRYPT_SECRET).eq(Boolean.TRUE));
    criteria.add(new DefaultEqualsExpressionFactory(ENCRYPTION_KEY_SIZE).eq(DEFAULT_ENCRYPTION_SIZE));
    criteria.add(new DefaultEqualsExpressionFactory(ENCRYPTION_KEY_ITERATIONS).eq(DEFAULT_ENCRYPTION_ITERATIONS));
    criteria.add(new DefaultEqualsExpressionFactory(ENCRYPTION_KEY_SALT).eq(saltGenerator.generate()));
    QueryString encryptionQueryParams=queryStringFactory.createQueryString(criteria);
    if (query == null) {
      CanonicalUri uri=new DefaultCanonicalUri(request.getUri().getAbsolutePath(),encryptionQueryParams);
      request=new DefaultResourceDataRequest(request.getAction(),uri,request.getResourceClass(),request.getData());
    }
 else {
      query.putAll(encryptionQueryParams);
    }
  }
  ResourceDataResult result=chain.filter(request);
  if (addEncryptionMetadata) {
    query=request.getUri().getQuery();
    Map<String,Object> encryptionMetadata=new LinkedHashMap<String,Object>();
    String salt=query.get(ENCRYPTION_KEY_SALT);
    Integer size=query.containsKey(ENCRYPTION_KEY_SIZE) ? Integer.valueOf(query.get(ENCRYPTION_KEY_SIZE)) : DEFAULT_ENCRYPTION_SIZE;
    Integer iterations=query.containsKey(ENCRYPTION_KEY_ITERATIONS) ? Integer.valueOf(query.get(ENCRYPTION_KEY_ITERATIONS)) : DEFAULT_ENCRYPTION_ITERATIONS;
    encryptionMetadata.put(ENCRYPTION_KEY_SALT,salt);
    encryptionMetadata.put(ENCRYPTION_KEY_SIZE,size);
    encryptionMetadata.put(ENCRYPTION_KEY_ITERATIONS,iterations);
    Map<String,Object> data=result.getData();
    if (DefaultApiKeyList.isCollectionResource(data)) {
      @SuppressWarnings("String_Node_Str") Collection<Map<String,Object>> items=(Collection<Map<String,Object>>)data.get(DefaultApiKeyList.ITEMS_PROPERTY_NAME);
      for (      Map<String,Object> item : items) {
        item.put(ENCRYPTION_METADATA,encryptionMetadata);
      }
    }
 else {
      data.put(ENCRYPTION_METADATA,encryptionMetadata);
    }
  }
  return result;
}