Program: 65522
Project: 65522
Buggy source:
protected void validateAbstractFromClause(AbstractFromClause expression){
  if (expression.hasDeclaration()) {
    validateCollectionSeparatedByComma(expression.getDeclaration(),AbstractFromClause_IdentificationVariableDeclarationEndsWithComma,AbstractFromClause_IdentificationVariableDeclarationIsMissingComma);
    List<Declaration> declarations=context.getDeclarations();
    for (int index=0, count=declarations.size(); index < count; index++) {
      Declaration declaration=declarations.get(index);
      if (declaration.isRange() && declaration.hasJoins()) {
        List<Map.Entry<Join,String>> joinEntries=declaration.getJoinEntries();
        for (int joinIndex=0, joinCount=joinEntries.size(); joinIndex < joinCount; joinIndex++) {
          Map.Entry<Join,String> joinEntry=joinEntries.get(joinIndex);
          Join join=joinEntry.getKey();
          String variableName=context.literal(join.getJoinAssociationPath(),LiteralType.PATH_EXPRESSION_IDENTIFICATION_VARIABLE);
          if (ExpressionTools.stringIsNotEmpty(variableName) && !isIdentificationVariableDeclaredBefore(variableName,index,joinIndex,declarations)) {
            int startPosition=position(join.getJoinAssociationPath());
            int endPosition=startPosition + variableName.length();
            addProblem(expression,startPosition,endPosition,AbstractFromClause_WrongOrderOfIdentificationVariableDeclaration,variableName);
          }
        }
      }
 else       if (!declaration.isRange()) {
        String variableName=context.literal(declaration.getBaseExpression(),LiteralType.PATH_EXPRESSION_IDENTIFICATION_VARIABLE);
        if (ExpressionTools.stringIsNotEmpty(variableName) && !isIdentificationVariableDeclaredBefore(variableName,index,-1,declarations)) {
          int startPosition=position(declaration.getDeclarationExpression()) - variableName.length();
          int endPosition=startPosition + variableName.length();
          addProblem(expression,startPosition,endPosition,AbstractFromClause_WrongOrderOfIdentificationVariableDeclaration,variableName);
        }
      }
    }
  }
 else {
    int startPosition=position(expression) + FROM.length();
    if (expression.hasSpaceAfterFrom()) {
      startPosition++;
    }
    int endPosition=startPosition;
    addProblem(expression,startPosition,endPosition,AbstractFromClause_MissingIdentificationVariableDeclaration);
  }
}

Fixed version (ground truth):
protected void validateAbstractFromClause(AbstractFromClause expression){
  if (expression.hasDeclaration()) {
    validateCollectionSeparatedByComma(expression.getDeclaration(),AbstractFromClause_IdentificationVariableDeclarationEndsWithComma,AbstractFromClause_IdentificationVariableDeclarationIsMissingComma);
    List<Declaration> declarations=context.getDeclarations();
    for (int index=0, count=declarations.size(); index < count; index++) {
      Declaration declaration=declarations.get(index);
      if (declaration.isRange() && declaration.hasJoins()) {
        List<Map.Entry<Join,String>> joinEntries=declaration.getJoinEntries();
        for (int joinIndex=0, joinCount=joinEntries.size(); joinIndex < joinCount; joinIndex++) {
          Map.Entry<Join,String> joinEntry=joinEntries.get(joinIndex);
          Join join=joinEntry.getKey();
          String variableName=context.literal(join.getJoinAssociationPath(),LiteralType.PATH_EXPRESSION_IDENTIFICATION_VARIABLE);
          if (ExpressionTools.stringIsNotEmpty(variableName) && isIdentificationVariableDeclaredAfter(variableName,index,joinIndex,declarations)) {
            int startPosition=position(join.getJoinAssociationPath());
            int endPosition=startPosition + variableName.length();
            addProblem(expression,startPosition,endPosition,AbstractFromClause_WrongOrderOfIdentificationVariableDeclaration,variableName);
          }
        }
      }
 else       if (!declaration.isRange()) {
        String variableName=context.literal(declaration.getBaseExpression(),LiteralType.PATH_EXPRESSION_IDENTIFICATION_VARIABLE);
        if (ExpressionTools.stringIsNotEmpty(variableName) && isIdentificationVariableDeclaredAfter(variableName,index,-1,declarations)) {
          int startPosition=position(declaration.getDeclarationExpression()) - variableName.length();
          int endPosition=startPosition + variableName.length();
          addProblem(expression,startPosition,endPosition,AbstractFromClause_WrongOrderOfIdentificationVariableDeclaration,variableName);
        }
      }
    }
  }
 else {
    int startPosition=position(expression) + FROM.length();
    if (expression.hasSpaceAfterFrom()) {
      startPosition++;
    }
    int endPosition=startPosition;
    addProblem(expression,startPosition,endPosition,AbstractFromClause_MissingIdentificationVariableDeclaration);
  }
}