Program: 60635
Project: 60635
Buggy source:
/** 
 * Find users by derived attribute value. This method could fail if one or more string literals contained into the derived attribute value provided derive from identifier (schema name) replacement. When you are going to specify a derived attribute expression you must be quite sure that string literals used to build the expression cannot be found into the attribute values used to replace attribute schema names used as identifiers.
 * @param schemaName derived schema name.
 * @param value derived attribute value.
 * @return list of users.
 * @throws InvalidSearchConditionException in case of errors retrievingschema names used to buid the derived schema expression.
 */
@Override public List<SyncopeUser> findByDerAttrValue(final String schemaName,final String value) throws InvalidSearchConditionException {
  UDerSchema schema=derSchemaDAO.find(schemaName,UDerSchema.class);
  if (schema == null) {
    LOG.error("String_Node_Str",schemaName);
    return Collections.EMPTY_LIST;
  }
  final StringBuilder querystring=new StringBuilder();
  boolean subquery=false;
  for (  String clause : getWhereClause(schema.getExpression(),value)) {
    if (querystring.length() > 0) {
      subquery=true;
      querystring.append("String_Node_Str");
    }
    querystring.append("String_Node_Str").append("String_Node_Str").append("String_Node_Str").append(clause);
    if (subquery) {
      querystring.append(')');
    }
  }
  LOG.debug("String_Node_Str",querystring);
  final Query query=entityManager.createNativeQuery(querystring.toString());
  final List<SyncopeUser> result=new ArrayList<SyncopeUser>();
  SyncopeUser user;
  for (  Object userId : query.getResultList()) {
    user=find(Long.parseLong(userId.toString()));
    if (!result.contains(user)) {
      result.add(user);
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Find users by derived attribute value. This method could fail if one or more string literals contained into the derived attribute value provided derive from identifier (schema name) replacement. When you are going to specify a derived attribute expression you must be quite sure that string literals used to build the expression cannot be found into the attribute values used to replace attribute schema names used as identifiers.
 * @param schemaName derived schema name.
 * @param value derived attribute value.
 * @return list of users.
 * @throws InvalidSearchConditionException in case of errors retrieving schema names used to buid the derived schemaexpression.
 */
@Override public List<SyncopeUser> findByDerAttrValue(final String schemaName,final String value) throws InvalidSearchConditionException {
  UDerSchema schema=derSchemaDAO.find(schemaName,UDerSchema.class);
  if (schema == null) {
    LOG.error("String_Node_Str",schemaName);
    return Collections.EMPTY_LIST;
  }
  final StringBuilder querystring=new StringBuilder();
  boolean subquery=false;
  for (  String clause : getWhereClause(schema.getExpression(),value)) {
    if (querystring.length() > 0) {
      subquery=true;
      querystring.append("String_Node_Str");
    }
    querystring.append("String_Node_Str").append("String_Node_Str").append("String_Node_Str").append(clause);
    if (subquery) {
      querystring.append(')');
    }
  }
  LOG.debug("String_Node_Str",querystring);
  final Query query=entityManager.createNativeQuery(querystring.toString());
  final List<SyncopeUser> result=new ArrayList<SyncopeUser>();
  SyncopeUser user;
  for (  Object userId : query.getResultList()) {
    user=find(Long.parseLong(userId.toString()));
    if (!result.contains(user)) {
      result.add(user);
    }
  }
  return result;
}