Program: 51356
Project: 51356
Buggy source:
/** 
 * Generates a multi-value IN expression corresponding to a list of member expressions, and adds the expression to the WHERE clause of a query, provided the member values are all non-null
 * @param sqlQuery query containing the where clause
 * @param levelToColumnMap where to find each level's key
 * @param relationNamesToStarTableMap map to disambiguate table aliases
 * @param members list of constraining members
 * @param fromLevel lowest parent level that is unique
 * @param restrictMemberTypes defines the behavior when calculated members are present
 * @param parentWithNullToChildrenMap upon return this map contains membersthat have Null values in its (parent) levels
 * @return a non-empty String if multi-value IN list was generated for some members.
 */
private static String generateMultiValueInExpr(SqlQuery sqlQuery,Map<RolapLevel,RolapStar.Column> levelToColumnMap,Map<String,RolapStar.Table> relationNamesToStarTableMap,List<RolapMember> members,RolapLevel fromLevel,boolean restrictMemberTypes,Map<RolapMember,List<RolapMember>> parentWithNullToChildrenMap){
  final StringBuilder columnBuf=new StringBuilder();
  final StringBuilder valueBuf=new StringBuilder();
  columnBuf.append("String_Node_Str");
  boolean isFirstLevelInMultiple=true;
  for (RolapMember m=members.get(0); m != null; m=m.getParentMember()) {
    if (m.isAll()) {
      continue;
    }
    RolapLevel level=m.getLevel();
    RolapHierarchy hierarchy=(RolapHierarchy)level.getHierarchy();
    RolapStar.Column column=levelToColumnMap.get(level);
    if (column != null && relationNamesToStarTableMap != null) {
      RolapStar.Table targetTable=column.getTable();
      hierarchy.addToFrom(sqlQuery,relationNamesToStarTableMap,targetTable);
    }
 else {
      hierarchy.addToFrom(sqlQuery,level.getKeyExp());
    }
    MondrianDef.Expression exp=level.getNameExp();
    if (exp == null) {
      exp=level.getKeyExp();
    }
    String columnString=level.getExpressionWithAlias(sqlQuery,levelToColumnMap,exp);
    if (!isFirstLevelInMultiple) {
      columnBuf.append("String_Node_Str");
    }
 else {
      isFirstLevelInMultiple=false;
    }
    columnBuf.append(columnString);
    if (m.getLevel() == fromLevel) {
      break;
    }
  }
  columnBuf.append("String_Node_Str");
  valueBuf.append("String_Node_Str");
  boolean isFirstMember=true;
  String memberString;
  for (  RolapMember m : members) {
    if (m.isCalculated()) {
      if (restrictMemberTypes) {
        throw Util.newInternal("String_Node_Str" + "String_Node_Str" + m);
      }
      continue;
    }
    isFirstLevelInMultiple=true;
    memberString="String_Node_Str";
    boolean memberSQLGenerated=false;
    boolean containsNull=false;
    for (RolapMember p=m; p != null; p=p.getParentMember()) {
      if (p.isAll()) {
        continue;
      }
      RolapLevel level=p.getLevel();
      String value=getColumnValue(p.getSqlKey(),sqlQuery.getDialect(),level.getDatatype());
      if (RolapUtil.mdxNullLiteral.equalsIgnoreCase(value)) {
        List<RolapMember> childrenList=parentWithNullToChildrenMap.get(p);
        if (childrenList == null) {
          childrenList=new ArrayList<RolapMember>();
        }
        childrenList.add(m);
        parentWithNullToChildrenMap.put(m.getParentMember(),childrenList);
        containsNull=true;
        break;
      }
      if (isFirstLevelInMultiple) {
        isFirstLevelInMultiple=false;
      }
 else {
        memberString+="String_Node_Str";
      }
      final StringBuilder buf=new StringBuilder();
      sqlQuery.getDialect().quote(buf,value,level.getDatatype());
      memberString+=buf.toString();
      memberSQLGenerated=true;
      if (p.getLevel() == fromLevel) {
        break;
      }
    }
    if (!containsNull && memberSQLGenerated) {
      memberString+="String_Node_Str";
      if (!isFirstMember) {
        valueBuf.append("String_Node_Str");
      }
      valueBuf.append(memberString);
      isFirstMember=false;
    }
  }
  String condition="String_Node_Str";
  if (!isFirstMember) {
    valueBuf.append("String_Node_Str");
    condition+=columnBuf.toString() + "String_Node_Str" + valueBuf.toString();
  }
  return condition;
}

Fixed version (ground truth):
/** 
 * Generates a multi-value IN expression corresponding to a list of member expressions, and adds the expression to the WHERE clause of a query, provided the member values are all non-null
 * @param sqlQuery query containing the where clause
 * @param levelToColumnMap where to find each level's key
 * @param relationNamesToStarTableMap map to disambiguate table aliases
 * @param members list of constraining members
 * @param fromLevel lowest parent level that is unique
 * @param restrictMemberTypes defines the behavior when calculated members are present
 * @param parentWithNullToChildrenMap upon return this map contains membersthat have Null values in its (parent) levels
 * @return a non-empty String if multi-value IN list was generated for some members.
 */
private static String generateMultiValueInExpr(SqlQuery sqlQuery,Map<RolapLevel,RolapStar.Column> levelToColumnMap,Map<String,RolapStar.Table> relationNamesToStarTableMap,List<RolapMember> members,RolapLevel fromLevel,boolean restrictMemberTypes,Map<RolapMember,List<RolapMember>> parentWithNullToChildrenMap){
  final StringBuilder columnBuf=new StringBuilder();
  final StringBuilder valueBuf=new StringBuilder();
  columnBuf.append("String_Node_Str");
  boolean isFirstLevelInMultiple=true;
  for (RolapMember m=members.get(0); m != null; m=m.getParentMember()) {
    if (m.isAll()) {
      continue;
    }
    RolapLevel level=m.getLevel();
    RolapHierarchy hierarchy=(RolapHierarchy)level.getHierarchy();
    RolapStar.Column column=levelToColumnMap.get(level);
    if (column != null && relationNamesToStarTableMap != null) {
      RolapStar.Table targetTable=column.getTable();
      hierarchy.addToFrom(sqlQuery,relationNamesToStarTableMap,targetTable);
    }
 else {
      hierarchy.addToFrom(sqlQuery,level.getKeyExp());
    }
    MondrianDef.Expression exp=level.getNameExp();
    if (exp == null) {
      exp=level.getKeyExp();
    }
    String columnString=level.getExpressionWithAlias(sqlQuery,levelToColumnMap,exp);
    if (!isFirstLevelInMultiple) {
      columnBuf.append("String_Node_Str");
    }
 else {
      isFirstLevelInMultiple=false;
    }
    columnBuf.append(columnString);
    if (m.getLevel() == fromLevel) {
      break;
    }
  }
  columnBuf.append("String_Node_Str");
  valueBuf.append("String_Node_Str");
  boolean isFirstMember=true;
  String memberString;
  for (  RolapMember m : members) {
    if (m.isCalculated()) {
      if (restrictMemberTypes) {
        throw Util.newInternal("String_Node_Str" + "String_Node_Str" + m);
      }
      continue;
    }
    isFirstLevelInMultiple=true;
    memberString="String_Node_Str";
    boolean memberSQLGenerated=false;
    boolean containsNull=false;
    for (RolapMember p=m; p != null; p=p.getParentMember()) {
      if (p.isAll()) {
        continue;
      }
      RolapLevel level=p.getLevel();
      String value=getColumnValue(p.getSqlKey(),sqlQuery.getDialect(),level.getDatatype());
      if (RolapUtil.mdxNullLiteral.equalsIgnoreCase(value)) {
        RolapMember mp=m.getParentMember();
        List<RolapMember> childrenList=parentWithNullToChildrenMap.get(mp);
        if (childrenList == null) {
          childrenList=new ArrayList<RolapMember>();
        }
        childrenList.add(m);
        parentWithNullToChildrenMap.put(mp,childrenList);
        containsNull=true;
        break;
      }
      if (isFirstLevelInMultiple) {
        isFirstLevelInMultiple=false;
      }
 else {
        memberString+="String_Node_Str";
      }
      final StringBuilder buf=new StringBuilder();
      sqlQuery.getDialect().quote(buf,value,level.getDatatype());
      memberString+=buf.toString();
      memberSQLGenerated=true;
      if (p.getLevel() == fromLevel) {
        break;
      }
    }
    if (!containsNull && memberSQLGenerated) {
      memberString+="String_Node_Str";
      if (!isFirstMember) {
        valueBuf.append("String_Node_Str");
      }
      valueBuf.append(memberString);
      isFirstMember=false;
    }
  }
  String condition="String_Node_Str";
  if (!isFirstMember) {
    valueBuf.append("String_Node_Str");
    condition+=columnBuf.toString() + "String_Node_Str" + valueBuf.toString();
  }
  return condition;
}