Program: 60636
Project: 60636
Buggy source:
/** 
 * Generate one where clause for each different attribute schema into the derived schema expression provided.
 * @param expression derived schema expression.
 * @param value derived attribute value.
 * @return where clauses to use to build the query.
 * @throws InvalidSearchConditionException in case of errors retrievingidentifiers.
 */
private Set<String> getWhereClause(final String expression,final String value) throws InvalidSearchConditionException {
  final Parser parser=new Parser(new StringReader(expression));
  final List<String> identifiers=new ArrayList<String>();
  final List<String> literals=new ArrayList<String>();
  Token token;
  while ((token=parser.getNextToken()) != null && StringUtils.hasText(token.toString())) {
    if (token.kind == ParserConstants.STRING_LITERAL) {
      literals.add(token.toString().substring(1,token.toString().length() - 1));
    }
    if (token.kind == ParserConstants.IDENTIFIER) {
      identifiers.add(token.toString());
    }
  }
  Collections.sort(literals,new Comparator<String>(){
    @Override public int compare(    String t,    String t1){
      if (t == null && t1 == null) {
        return 0;
      }
      if (t != null && t1 == null) {
        return -1;
      }
      if (t == null && t1 != null) {
        return 1;
      }
      if (t.length() == t1.length()) {
        return 0;
      }
      if (t.length() > t1.length()) {
        return -1;
      }
 else {
        return 1;
      }
    }
  }
);
  final List<String> attrValues=split(value,literals);
  if (attrValues.size() != identifiers.size()) {
    LOG.error("String_Node_Str");
    throw new InvalidSearchConditionException("String_Node_Str");
  }
  final Set<String> clauses=new HashSet<String>();
  final StringBuilder bld=new StringBuilder();
  final Set<String> used=new HashSet<String>();
  USchema schema;
  for (int i=0; i < identifiers.size(); i++) {
    if (!used.contains(identifiers.get(i))) {
      schema=schemaDAO.find(identifiers.get(i),USchema.class);
      if (schema == null) {
        LOG.error("String_Node_Str",identifiers.get(i));
        throw new InvalidSearchConditionException("String_Node_Str" + identifiers.get(i));
      }
      bld.delete(0,bld.length());
      bld.append("String_Node_Str");
      bld.append("String_Node_Str").append(identifiers.get(i)).append("String_Node_Str");
      bld.append("String_Node_Str");
      bld.append("String_Node_Str").append("String_Node_Str");
      bld.append("String_Node_Str");
      bld.append("String_Node_Str");
switch (schema.getType()) {
case Boolean:
        bld.append("String_Node_Str").append(attrValues.get(i)).append("String_Node_Str");
      break;
case Long:
    bld.append("String_Node_Str").append(attrValues.get(i));
  break;
case Double:
bld.append("String_Node_Str").append(attrValues.get(i));
break;
case Date:
bld.append("String_Node_Str").append(attrValues.get(i)).append("String_Node_Str");
break;
default :
bld.append("String_Node_Str").append(attrValues.get(i)).append("String_Node_Str");
}
bld.append("String_Node_Str");
used.add(identifiers.get(i));
clauses.add(bld.toString());
}
}
LOG.debug("String_Node_Str",clauses);
return clauses;
}

Fixed version (ground truth):
/** 
 * Generate one where clause for each different attribute schema into the derived schema expression provided.
 * @param expression derived schema expression.
 * @param value derived attribute value.
 * @return where clauses to use to build the query.
 * @throws InvalidSearchConditionException in case of errors retrieving identifiers.
 */
private Set<String> getWhereClause(final String expression,final String value) throws InvalidSearchConditionException {
  final Parser parser=new Parser(new StringReader(expression));
  final List<String> identifiers=new ArrayList<String>();
  final List<String> literals=new ArrayList<String>();
  Token token;
  while ((token=parser.getNextToken()) != null && StringUtils.hasText(token.toString())) {
    if (token.kind == ParserConstants.STRING_LITERAL) {
      literals.add(token.toString().substring(1,token.toString().length() - 1));
    }
    if (token.kind == ParserConstants.IDENTIFIER) {
      identifiers.add(token.toString());
    }
  }
  Collections.sort(literals,new Comparator<String>(){
    @Override public int compare(    String t,    String t1){
      if (t == null && t1 == null) {
        return 0;
      }
      if (t != null && t1 == null) {
        return -1;
      }
      if (t == null && t1 != null) {
        return 1;
      }
      if (t.length() == t1.length()) {
        return 0;
      }
      if (t.length() > t1.length()) {
        return -1;
      }
 else {
        return 1;
      }
    }
  }
);
  final List<String> attrValues=split(value,literals);
  if (attrValues.size() != identifiers.size()) {
    LOG.error("String_Node_Str");
    throw new InvalidSearchConditionException("String_Node_Str");
  }
  final Set<String> clauses=new HashSet<String>();
  final StringBuilder bld=new StringBuilder();
  final Set<String> used=new HashSet<String>();
  USchema schema;
  for (int i=0; i < identifiers.size(); i++) {
    if (!used.contains(identifiers.get(i))) {
      schema=schemaDAO.find(identifiers.get(i),USchema.class);
      if (schema == null) {
        LOG.error("String_Node_Str",identifiers.get(i));
        throw new InvalidSearchConditionException("String_Node_Str" + identifiers.get(i));
      }
      bld.delete(0,bld.length());
      bld.append("String_Node_Str");
      bld.append("String_Node_Str").append(identifiers.get(i)).append("String_Node_Str");
      bld.append("String_Node_Str");
      bld.append("String_Node_Str").append("String_Node_Str");
      bld.append("String_Node_Str");
      bld.append("String_Node_Str");
switch (schema.getType()) {
case Boolean:
        bld.append("String_Node_Str").append(attrValues.get(i)).append("String_Node_Str");
      break;
case Long:
    bld.append("String_Node_Str").append(attrValues.get(i));
  break;
case Double:
bld.append("String_Node_Str").append(attrValues.get(i));
break;
case Date:
bld.append("String_Node_Str").append(attrValues.get(i)).append("String_Node_Str");
break;
default :
bld.append("String_Node_Str").append(attrValues.get(i)).append("String_Node_Str");
}
bld.append("String_Node_Str");
used.add(identifiers.get(i));
clauses.add(bld.toString());
}
}
LOG.debug("String_Node_Str",clauses);
return clauses;
}