Program: 65185
Project: 65185
Buggy source:
/** 
 * Validates the left and right expressions of the given   {@link ComparisonExpression}. The tests to perform are: <ul> <li>If the comparison operator is either '=' or '<>'. The expressions can only be <ul> <li>Two identification variables;</li> <li>Two path expressions resolving to an association field;</li> <li>One can be a path expression resolving to a basic field and the other one has to resolve to a basic value.</li> </ul> </li> <li>If the comparison operator is either '<', '<=', '>=', '>'. The expressions cannot be <ul> <li>Two identification variables;</li> <li>Two path expressions resolving to an association field;</li> </ul> </li> </ul>
 * @param expression The {@link ConcatExpression} to validate by validating itsleft and right expressions
 * @return The status of the comparison between the left and right expression: <code>true</code>if the two expressions pass the rules defined by this method; <code>false</code> otherwise
 */
protected boolean validateComparisonExpression(ComparisonExpression expression){
  Expression leftExpression=expression.getLeftExpression();
  Expression rightExpression=expression.getRightExpression();
  boolean valid=true;
  ComparisonExpressionVisitor validator=getComparisonExpressionVisitor();
  try {
    validator.validatingLeftExpression=true;
    leftExpression.accept(validator);
    validator.validatingLeftExpression=false;
    rightExpression.accept(validator);
    if (isOrderComparison(expression)) {
      if (validator.leftIdentificationVariable && validator.leftIdentificationVariableValid) {
        IdentificationVariable variable=(IdentificationVariable)leftExpression;
        if (!isIdentificationVariableValidInComparison(variable)) {
          addProblem(leftExpression,ComparisonExpression_IdentificationVariable,leftExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
 else       if (validator.leftStateFieldPathExpression && validator.leftStateFieldPathExpressionValid) {
        Object mapping=helper.resolveMapping(leftExpression);
        if ((mapping != null) && !helper.isPropertyMapping(mapping)) {
          addProblem(leftExpression,ComparisonExpression_AssociationField,leftExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
      if (validator.rightIdentificationVariable && validator.rightIdentificationVariableValid) {
        IdentificationVariable variable=(IdentificationVariable)rightExpression;
        if (!isIdentificationVariableValidInComparison(variable)) {
          addProblem(rightExpression,ComparisonExpression_IdentificationVariable,rightExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
 else       if (validator.rightStateFieldPathExpression && validator.rightStateFieldPathExpressionValid) {
        Object mapping=helper.resolveMapping(rightExpression);
        if ((mapping != null) && !helper.isPropertyMapping(mapping)) {
          addProblem(rightExpression,ComparisonExpression_AssociationField,rightExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
    }
 else {
      if (validator.leftIdentificationVariable && validator.leftIdentificationVariableValid && validator.rightStateFieldPathExpression&& validator.rightStateFieldPathExpressionValid) {
        Object mapping=helper.resolveMapping(rightExpression);
        if ((mapping != null) && helper.isPropertyMapping(mapping)) {
          addProblem(rightExpression,ComparisonExpression_BasicField,rightExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
 else       if (validator.rightIdentificationVariable && validator.rightIdentificationVariableValid && validator.leftStateFieldPathExpression&& validator.leftStateFieldPathExpressionValid) {
        Object mapping=helper.resolveMapping(leftExpression);
        if ((mapping != null) && helper.isPropertyMapping(mapping)) {
          addProblem(leftExpression,ComparisonExpression_BasicField,leftExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
    }
    return valid;
  }
  finally {
    validator.dispose();
  }
}

Fixed version (ground truth):
/** 
 * Validates the left and right expressions of the given   {@link ComparisonExpression}. The tests to perform are: <ul> <li>If the comparison operator is either '=' or '<>'. The expressions can only be <ul> <li>Two identification variables;</li> <li>Two path expressions resolving to an association field;</li> <li>One can be a path expression resolving to a basic field and the other one has to resolve to a basic value.</li> </ul> </li> <li>If the comparison operator is either '<', '<=', '>=', '>'. The expressions cannot be <ul> <li>Two identification variables;</li> <li>Two path expressions resolving to an association field;</li> </ul> </li> </ul>
 * @param expression The {@link ConcatExpression} to validate by validating itsleft and right expressions
 * @return The status of the comparison between the left and right expression: <code>true</code>if the two expressions pass the rules defined by this method; <code>false</code> otherwise
 */
protected boolean validateComparisonExpression(ComparisonExpression expression){
  Expression leftExpression=expression.getLeftExpression();
  Expression rightExpression=expression.getRightExpression();
  boolean valid=true;
  ComparisonExpressionVisitor validator=getComparisonExpressionVisitor();
  try {
    validator.validatingLeftExpression=true;
    leftExpression.accept(validator);
    validator.validatingLeftExpression=false;
    rightExpression.accept(validator);
    if (isOrderComparison(expression)) {
      if (validator.leftIdentificationVariable && validator.leftIdentificationVariableValid) {
        IdentificationVariable variable=(IdentificationVariable)leftExpression;
        if (!isIdentificationVariableValidInComparison(variable)) {
          addProblem(leftExpression,ComparisonExpression_IdentificationVariable,leftExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
 else       if (validator.leftStateFieldPathExpression && validator.leftStateFieldPathExpressionValid) {
        Object mapping=helper.resolveMapping(leftExpression);
        if ((mapping != null) && !helper.isPropertyMapping(mapping)) {
          addProblem(leftExpression,ComparisonExpression_AssociationField,leftExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
      if (validator.rightIdentificationVariable && validator.rightIdentificationVariableValid) {
        IdentificationVariable variable=(IdentificationVariable)rightExpression;
        if (!isIdentificationVariableValidInComparison(variable)) {
          addProblem(rightExpression,ComparisonExpression_IdentificationVariable,rightExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
 else       if (validator.rightStateFieldPathExpression && validator.rightStateFieldPathExpressionValid) {
        Object mapping=helper.resolveMapping(rightExpression);
        if ((mapping != null) && !helper.isPropertyMapping(mapping)) {
          addProblem(rightExpression,ComparisonExpression_AssociationField,rightExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
    }
 else {
      if (validator.leftIdentificationVariable && validator.leftIdentificationVariableValid && validator.rightStateFieldPathExpression&& validator.rightStateFieldPathExpressionValid) {
        Object mapping=helper.resolveMapping(rightExpression);
        IdentificationVariable variable=(IdentificationVariable)leftExpression;
        if ((mapping != null) && helper.isPropertyMapping(mapping) && !isIdentificationVariableValidInComparison(variable)) {
          addProblem(rightExpression,ComparisonExpression_BasicField,rightExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
 else       if (validator.rightIdentificationVariable && validator.rightIdentificationVariableValid && validator.leftStateFieldPathExpression&& validator.leftStateFieldPathExpressionValid) {
        Object mapping=helper.resolveMapping(leftExpression);
        IdentificationVariable variable=(IdentificationVariable)rightExpression;
        if ((mapping != null) && helper.isPropertyMapping(mapping) && !isIdentificationVariableValidInComparison(variable)) {
          addProblem(leftExpression,ComparisonExpression_BasicField,leftExpression.toActualText(),expression.getComparisonOperator());
          valid=false;
        }
      }
    }
    return valid;
  }
  finally {
    validator.dispose();
  }
}