Program: 34973
Project: 34973
Buggy source:
/** 
 * This method returns the parsed where condition corresponding to the filter input in the user query.
 * @param whereExpression
 * @return Parsed where condition String
 * @throws ODataException
 */
public static String parseToJPAWhereExpression(final CommonExpression whereExpression,final String tableAlias) throws ODataException {
switch (whereExpression.getKind()) {
case UNARY:
    final UnaryExpression unaryExpression=(UnaryExpression)whereExpression;
  final String operand=parseToJPAWhereExpression(unaryExpression.getOperand(),tableAlias);
switch (unaryExpression.getOperator()) {
case NOT:
  return JPQLStatement.Operator.NOT + "String_Node_Str" + operand+ "String_Node_Str";
case MINUS:
if (operand.startsWith("String_Node_Str")) {
  return operand.substring(1);
}
 else {
  return "String_Node_Str" + operand;
}
default :
throw new ODataNotImplementedException();
}
case FILTER:
return parseToJPAWhereExpression(((FilterExpression)whereExpression).getExpression(),tableAlias);
case BINARY:
final BinaryExpression binaryExpression=(BinaryExpression)whereExpression;
if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression)binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) {
methodFlag=1;
}
final String left=parseToJPAWhereExpression(binaryExpression.getLeftOperand(),tableAlias);
final String right=parseToJPAWhereExpression(binaryExpression.getRightOperand(),tableAlias);
switch (binaryExpression.getOperator()) {
case AND:
return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND+ JPQLStatement.DELIMITER.SPACE+ right;
case OR:
return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR+ JPQLStatement.DELIMITER.SPACE+ right;
case EQ:
return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ+ JPQLStatement.DELIMITER.SPACE+ right;
case NE:
return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE+ JPQLStatement.DELIMITER.SPACE+ right;
case LT:
return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT+ JPQLStatement.DELIMITER.SPACE+ right;
case LE:
return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE+ JPQLStatement.DELIMITER.SPACE+ right;
case GT:
return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT+ JPQLStatement.DELIMITER.SPACE+ right;
case GE:
return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE+ JPQLStatement.DELIMITER.SPACE+ right;
case PROPERTY_ACCESS:
throw new ODataNotImplementedException();
default :
throw new ODataNotImplementedException();
}
case PROPERTY:
String returnStr=tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty)((PropertyExpression)whereExpression).getEdmProperty()).getMapping().getInternalName();
return returnStr;
case MEMBER:
String memberExpStr=EMPTY;
int i=0;
MemberExpression member=null;
CommonExpression tempExp=whereExpression;
while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) {
member=(MemberExpression)tempExp;
if (i > 0) {
memberExpStr=JPQLStatement.DELIMITER.PERIOD + memberExpStr;
}
i++;
memberExpStr=((EdmProperty)((PropertyExpression)member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr;
tempExp=member.getPath();
}
memberExpStr=((EdmProperty)((PropertyExpression)tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr;
return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr;
case LITERAL:
final LiteralExpression literal=(LiteralExpression)whereExpression;
final EdmSimpleType literalType=(EdmSimpleType)literal.getEdmType();
String value=literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(),EdmLiteralKind.URI,null,literalType.getDefaultType()),EdmLiteralKind.DEFAULT,null);
return evaluateComparingExpression(value,literalType);
case METHOD:
final MethodExpression methodExpression=(MethodExpression)whereExpression;
String first=parseToJPAWhereExpression(methodExpression.getParameters().get(0),tableAlias);
final String second=methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1),tableAlias) : null;
String third=methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2),tableAlias) : null;
switch (methodExpression.getMethod()) {
case SUBSTRING:
third=third != null ? "String_Node_Str" + third : "String_Node_Str";
return String.format("String_Node_Str",first,second,third);
case SUBSTRINGOF:
first=first.substring(1,first.length() - 1);
if (methodFlag == 1) {
methodFlag=0;
return String.format("String_Node_Str",second,first);
}
 else {
return String.format("String_Node_Str",second,first);
}
case TOLOWER:
return String.format("String_Node_Str",first);
default :
throw new ODataNotImplementedException();
}
default :
throw new ODataNotImplementedException();
}
}

Fixed version (ground truth):
/** 
 * This method returns the parsed where condition corresponding to the filter input in the user query.
 * @param whereExpression
 * @return Parsed where condition String
 * @throws ODataException
 */
public static String parseToJPAWhereExpression(final CommonExpression whereExpression,final String tableAlias) throws ODataException {
switch (whereExpression.getKind()) {
case UNARY:
    final UnaryExpression unaryExpression=(UnaryExpression)whereExpression;
  final String operand=parseToJPAWhereExpression(unaryExpression.getOperand(),tableAlias);
switch (unaryExpression.getOperator()) {
case NOT:
  return JPQLStatement.Operator.NOT + JPQLStatement.DELIMITER.PARENTHESIS_LEFT + operand+ JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
case MINUS:
if (operand.startsWith("String_Node_Str")) {
  return operand.substring(1);
}
 else {
  return "String_Node_Str" + operand;
}
default :
throw new ODataNotImplementedException();
}
case FILTER:
return parseToJPAWhereExpression(((FilterExpression)whereExpression).getExpression(),tableAlias);
case BINARY:
final BinaryExpression binaryExpression=(BinaryExpression)whereExpression;
if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD) && ((binaryExpression.getOperator() == BinaryOperator.EQ) || (binaryExpression.getOperator() == BinaryOperator.NE)) && (((MethodExpression)binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) {
methodFlag=1;
}
final String left=parseToJPAWhereExpression(binaryExpression.getLeftOperand(),tableAlias);
final String right=parseToJPAWhereExpression(binaryExpression.getRightOperand(),tableAlias);
switch (binaryExpression.getOperator()) {
case AND:
return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE+ JPQLStatement.Operator.AND+ JPQLStatement.DELIMITER.SPACE+ right+ JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
case OR:
return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE+ JPQLStatement.Operator.OR+ JPQLStatement.DELIMITER.SPACE+ right+ JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
case EQ:
return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE+ JPQLStatement.Operator.EQ+ JPQLStatement.DELIMITER.SPACE+ right+ JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
case NE:
return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE+ JPQLStatement.Operator.NE+ JPQLStatement.DELIMITER.SPACE+ right+ JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
case LT:
return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE+ JPQLStatement.Operator.LT+ JPQLStatement.DELIMITER.SPACE+ right+ JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
case LE:
return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE+ JPQLStatement.Operator.LE+ JPQLStatement.DELIMITER.SPACE+ right+ JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
case GT:
return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE+ JPQLStatement.Operator.GT+ JPQLStatement.DELIMITER.SPACE+ right+ JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
case GE:
return JPQLStatement.DELIMITER.PARENTHESIS_LEFT + left + JPQLStatement.DELIMITER.SPACE+ JPQLStatement.Operator.GE+ JPQLStatement.DELIMITER.SPACE+ right+ JPQLStatement.DELIMITER.PARENTHESIS_RIGHT;
case PROPERTY_ACCESS:
throw new ODataNotImplementedException();
default :
throw new ODataNotImplementedException();
}
case PROPERTY:
String returnStr=tableAlias + JPQLStatement.DELIMITER.PERIOD + ((EdmProperty)((PropertyExpression)whereExpression).getEdmProperty()).getMapping().getInternalName();
return returnStr;
case MEMBER:
String memberExpStr=EMPTY;
int i=0;
MemberExpression member=null;
CommonExpression tempExp=whereExpression;
while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) {
member=(MemberExpression)tempExp;
if (i > 0) {
memberExpStr=JPQLStatement.DELIMITER.PERIOD + memberExpStr;
}
i++;
memberExpStr=((EdmProperty)((PropertyExpression)member.getProperty()).getEdmProperty()).getMapping().getInternalName() + memberExpStr;
tempExp=member.getPath();
}
memberExpStr=((EdmProperty)((PropertyExpression)tempExp).getEdmProperty()).getMapping().getInternalName() + JPQLStatement.DELIMITER.PERIOD + memberExpStr;
return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr;
case LITERAL:
final LiteralExpression literal=(LiteralExpression)whereExpression;
final EdmSimpleType literalType=(EdmSimpleType)literal.getEdmType();
String value=literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(),EdmLiteralKind.URI,null,literalType.getDefaultType()),EdmLiteralKind.DEFAULT,null);
return evaluateComparingExpression(value,literalType);
case METHOD:
final MethodExpression methodExpression=(MethodExpression)whereExpression;
String first=parseToJPAWhereExpression(methodExpression.getParameters().get(0),tableAlias);
final String second=methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1),tableAlias) : null;
String third=methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2),tableAlias) : null;
switch (methodExpression.getMethod()) {
case SUBSTRING:
third=third != null ? "String_Node_Str" + third : "String_Node_Str";
return String.format("String_Node_Str",first,second,third);
case SUBSTRINGOF:
first=first.substring(1,first.length() - 1);
if (methodFlag == 1) {
methodFlag=0;
return String.format("String_Node_Str",second,first);
}
 else {
return String.format("String_Node_Str",second,first);
}
case TOLOWER:
return String.format("String_Node_Str",first);
default :
throw new ODataNotImplementedException();
}
default :
throw new ODataNotImplementedException();
}
}