Program: 50919
Project: 50919
Buggy source:
/** 
 * For every restricting member in the current context, generates a WHERE condition and a join to the fact table.
 * @param sqlQuery the query to modify
 * @param aggStar Aggregate table, or null if query is against fact table
 * @param restrictMemberTypes defines the behavior if the current contextcontains calculated members. If true, thows an exception.
 * @param evaluator Evaluator
 */
public static void addContextConstraint(SqlQuery sqlQuery,AggStar aggStar,Evaluator evaluator,boolean restrictMemberTypes){
  Member[] members=evaluator.getNonAllMembers();
  RolapCube baseCube=null;
  if (evaluator instanceof RolapEvaluator)   baseCube=((RolapEvaluator)evaluator).getCube();
  Map<RelationOrJoin,Set<RolapMember>> mapOfSlicerMembers=new HashMap<RelationOrJoin,Set<RolapMember>>();
  Map<RelationOrJoin,Boolean> done=new HashMap<RelationOrJoin,Boolean>();
  if (restrictMemberTypes) {
    if (containsCalculatedMember(members)) {
      throw Util.newInternal("String_Node_Str");
    }
    if (hasMultiPositionSlicer(evaluator)) {
      List<Member> slicerMembers=((RolapEvaluator)evaluator).getSlicerMembers();
      for (      Member slicerMember : slicerMembers) {
        RelationOrJoin rel=((RolapCubeHierarchy)slicerMember.getHierarchy()).getRelation();
        if (!mapOfSlicerMembers.containsKey(rel)) {
          mapOfSlicerMembers.put(rel,new HashSet<RolapMember>());
        }
        mapOfSlicerMembers.get(rel).add((RolapMember)slicerMember);
      }
    }
  }
 else {
    members=removeCalculatedAndDefaultMembers(members);
    members=removeMultiPositionSlicerMembers(members,evaluator);
  }
  final CellRequest request=RolapAggregationManager.makeRequest(members);
  if (request == null) {
    if (restrictMemberTypes) {
      throw Util.newInternal("String_Node_Str");
    }
    return;
  }
  RolapStar.Column[] columns=request.getConstrainedColumns();
  Object[] values=request.getSingleValues();
  int arity=columns.length;
  for (int i=0; i < arity; i++) {
    RolapStar.Column column=columns[i];
    String expr;
    if (aggStar != null) {
      int bitPos=column.getBitPosition();
      AggStar.Table.Column aggColumn=aggStar.lookupColumn(bitPos);
      AggStar.Table table=aggColumn.getTable();
      table.addToFrom(sqlQuery,false,true);
      expr=aggColumn.generateExprString(sqlQuery);
    }
 else {
      RolapStar.Table table=column.getTable();
      table.addToFrom(sqlQuery,false,true);
      expr=column.generateExprString(sqlQuery);
    }
    final String value=String.valueOf(values[i]);
    if ((RolapUtil.mdxNullLiteral().equalsIgnoreCase(value)) || (value.equalsIgnoreCase(RolapUtil.sqlNullValue.toString()))) {
      sqlQuery.addWhere(expr,"String_Node_Str",RolapUtil.sqlNullLiteral);
    }
 else {
      if (column.getDatatype().isNumeric()) {
        Double.valueOf(value);
      }
      if (mapOfSlicerMembers.containsKey(column.getTable().getRelation())) {
        if (!done.containsKey(column.getTable().getRelation())) {
          Set<RolapMember> slicerMembersArray=mapOfSlicerMembers.get(column.getTable().getRelation());
          List<RolapMember> slicerMembers=new ArrayList<RolapMember>(slicerMembersArray);
          final String where=generateMultiValueInExpr(sqlQuery,baseCube,aggStar,slicerMembers,(RolapLevel)slicerMembers.get(0).getHierarchy().getLevels()[0],restrictMemberTypes,null);
          sqlQuery.addWhere(where);
          done.put(column.getTable().getRelation(),Boolean.TRUE);
        }
      }
 else {
        final StringBuilder buf=new StringBuilder();
        sqlQuery.getDialect().quote(buf,value,column.getDatatype());
        sqlQuery.addWhere(expr,"String_Node_Str",buf.toString());
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * For every restricting member in the current context, generates a WHERE condition and a join to the fact table.
 * @param sqlQuery the query to modify
 * @param aggStar Aggregate table, or null if query is against fact table
 * @param restrictMemberTypes defines the behavior if the current contextcontains calculated members. If true, thows an exception.
 * @param evaluator Evaluator
 */
public static void addContextConstraint(SqlQuery sqlQuery,AggStar aggStar,Evaluator evaluator,boolean restrictMemberTypes){
  Member[] members=evaluator.getNonAllMembers();
  RolapCube baseCube=null;
  if (evaluator instanceof RolapEvaluator)   baseCube=((RolapEvaluator)evaluator).getCube();
  Map<RelationOrJoin,Set<RolapMember>> mapOfSlicerMembers=new HashMap<RelationOrJoin,Set<RolapMember>>();
  Map<RelationOrJoin,Boolean> done=new HashMap<RelationOrJoin,Boolean>();
  if (restrictMemberTypes) {
    if (containsCalculatedMember(members)) {
      throw Util.newInternal("String_Node_Str");
    }
    if (hasMultiPositionSlicer(evaluator)) {
      List<Member> slicerMembers=((RolapEvaluator)evaluator).getSlicerMembers();
      for (      Member slicerMember : slicerMembers) {
        RelationOrJoin rel=((RolapCubeHierarchy)slicerMember.getHierarchy()).getRelation();
        if (!mapOfSlicerMembers.containsKey(rel)) {
          mapOfSlicerMembers.put(rel,new HashSet<RolapMember>());
        }
        mapOfSlicerMembers.get(rel).add((RolapMember)slicerMember);
      }
    }
  }
 else {
    members=removeCalculatedAndDefaultMembers(members);
    members=removeMultiPositionSlicerMembers(members,evaluator);
  }
  final CellRequest request=RolapAggregationManager.makeRequest(members);
  if (request == null) {
    if (restrictMemberTypes) {
      throw Util.newInternal("String_Node_Str");
    }
    return;
  }
  RolapStar.Column[] columns=request.getConstrainedColumns();
  Object[] values=request.getSingleValues();
  int arity=columns.length;
  for (int i=0; i < arity; i++) {
    RolapStar.Column column=columns[i];
    String expr;
    if (aggStar != null) {
      int bitPos=column.getBitPosition();
      AggStar.Table.Column aggColumn=aggStar.lookupColumn(bitPos);
      AggStar.Table table=aggColumn.getTable();
      table.addToFrom(sqlQuery,false,true);
      expr=aggColumn.generateExprString(sqlQuery);
    }
 else {
      RolapStar.Table table=column.getTable();
      table.addToFrom(sqlQuery,false,true);
      expr=column.generateExprString(sqlQuery);
    }
    final String value=String.valueOf(values[i]);
    if ((RolapUtil.mdxNullLiteral().equalsIgnoreCase(value)) || (value.equalsIgnoreCase(RolapUtil.sqlNullValue.toString()))) {
      sqlQuery.addWhere(expr,"String_Node_Str",RolapUtil.sqlNullLiteral);
    }
 else {
      if (column.getDatatype().isNumeric()) {
        Double.valueOf(value);
      }
      if (mapOfSlicerMembers.containsKey(column.getTable().getRelation())) {
        if (!done.containsKey(column.getTable().getRelation())) {
          Set<RolapMember> slicerMembersArray=mapOfSlicerMembers.get(column.getTable().getRelation());
          List<RolapMember> slicerMembers=new ArrayList<RolapMember>(slicerMembersArray);
          RolapMember allMember=null;
          for (          RolapMember slicerMember : slicerMembers) {
            if (slicerMember.isAll()) {
              allMember=slicerMember;
              break;
            }
          }
          if (allMember != null) {
            slicerMembers.remove(allMember);
          }
          if (slicerMembers.size() > 0) {
            final String where=generateMultiValueInExpr(sqlQuery,baseCube,aggStar,slicerMembers,(RolapLevel)slicerMembers.get(0).getHierarchy().getLevels()[0],restrictMemberTypes,null);
            sqlQuery.addWhere(where);
          }
 else {
            final StringBuilder buf=new StringBuilder();
            sqlQuery.getDialect().quote(buf,value,column.getDatatype());
            sqlQuery.addWhere(expr,"String_Node_Str",buf.toString());
          }
          done.put(column.getTable().getRelation(),Boolean.TRUE);
        }
      }
 else {
        final StringBuilder buf=new StringBuilder();
        sqlQuery.getDialect().quote(buf,value,column.getDatatype());
        sqlQuery.addWhere(expr,"String_Node_Str",buf.toString());
      }
    }
  }
}