Program: 51339
Project: 51339
Buggy source:
/** 
 * Loads data for all the segments of the GroupingSets. If the grouping sets list contains more than one Grouping Set then data is loaded using the GROUP BY GROUPING SETS sql. Else if only one grouping set is passed in the list data is loaded without using GROUP BY GROUPING SETS sql. If the database does not support grouping sets  {@link mondrian.rolap.sql.SqlQuery.Dialect#supportsGroupingSets()} thengrouping sets list should always have only one element in it. <p>For example, if list has 2 grouping sets with columns A, B, C and B, C respectively, then the SQL will be "GROUP BY GROUPING SETS ((A, B, C), (B, C))". <p>Else if the list has only one grouping set then sql would be without grouping sets. <p>The <code>groupingSets</code> list should be topological order, with more detailed higher-level grouping sets occuring first. In other words, the first element of the list should always be the detailed grouping set (default grouping set), followed by grouping sets which can be rolled-up on this detailed grouping set. In the example (A, B, C) is the detailed grouping set and (B, C) is rolled-up using the detailed.
 * @param groupingSets   List of grouping sets whose segments are loaded
 * @param pinnedSegments Pinned segments
 */
public void load(List<GroupingSet> groupingSets,RolapAggregationManager.PinSet pinnedSegments){
  GroupingSetsList groupingSetsList=new GroupingSetsList(groupingSets);
  boolean useGroupingSet=groupingSetsList.useGroupingSets();
  RolapStar.Column[] defaultColumns=groupingSetsList.getDefaultColumns();
  SqlStatement stmt=null;
  try {
    stmt=createExecuteSql(groupingSetsList);
    int arity=defaultColumns.length;
    SortedSet<Comparable<?>>[] axisValueSets=getDistinctValueWorkspace(arity);
    boolean[] axisContainsNull=new boolean[arity];
    List<Object[]> rows=processData(stmt,axisContainsNull,axisValueSets,groupingSetsList);
    boolean sparse=setAxisDataAndDecideSparseUse(axisValueSets,axisContainsNull,groupingSetsList,rows);
    SegmentDataset[] nonGroupingDataSets=null;
    final Map<BitKey,SegmentDataset[]> groupingDataSetsMap=new HashMap<BitKey,SegmentDataset[]>();
    if (useGroupingSet) {
      populateDataSetMapOnGroupingColumnsBitKeys(groupingSetsList,sparse,groupingDataSetsMap);
    }
 else {
      nonGroupingDataSets=createDataSets(sparse,groupingSetsList.getDefaultSegments(),groupingSetsList.getDefaultAxes());
    }
    loadDataToDataSets(groupingSetsList,rows,groupingDataSetsMap,nonGroupingDataSets,axisContainsNull,sparse);
    setDataToSegments(groupingSetsList,nonGroupingDataSets,groupingDataSetsMap,pinnedSegments);
  }
 catch (  SQLException e) {
    throw stmt.handle(e);
  }
catch (  RuntimeException e) {
    throw e;
  }
 finally {
    if (stmt != null) {
      stmt.close();
    }
    setFailOnStillLoadingSegments(groupingSetsList);
  }
}

Fixed version (ground truth):
/** 
 * Loads data for all the segments of the GroupingSets. If the grouping sets list contains more than one Grouping Set then data is loaded using the GROUP BY GROUPING SETS sql. Else if only one grouping set is passed in the list data is loaded without using GROUP BY GROUPING SETS sql. If the database does not support grouping sets  {@link mondrian.rolap.sql.SqlQuery.Dialect#supportsGroupingSets()} thengrouping sets list should always have only one element in it. <p>For example, if list has 2 grouping sets with columns A, B, C and B, C respectively, then the SQL will be "GROUP BY GROUPING SETS ((A, B, C), (B, C))". <p>Else if the list has only one grouping set then sql would be without grouping sets. <p>The <code>groupingSets</code> list should be topological order, with more detailed higher-level grouping sets occuring first. In other words, the first element of the list should always be the detailed grouping set (default grouping set), followed by grouping sets which can be rolled-up on this detailed grouping set. In the example (A, B, C) is the detailed grouping set and (B, C) is rolled-up using the detailed.
 * @param groupingSets   List of grouping sets whose segments are loaded
 * @param pinnedSegments Pinned segments
 */
public void load(List<GroupingSet> groupingSets,RolapAggregationManager.PinSet pinnedSegments){
  GroupingSetsList groupingSetsList=new GroupingSetsList(groupingSets);
  boolean useGroupingSet=groupingSetsList.useGroupingSets();
  RolapStar.Column[] defaultColumns=groupingSetsList.getDefaultColumns();
  SqlStatement stmt=null;
  try {
    stmt=createExecuteSql(groupingSetsList);
    int arity=defaultColumns.length;
    SortedSet<Comparable<?>>[] axisValueSets=getDistinctValueWorkspace(arity);
    boolean[] axisContainsNull=new boolean[arity];
    List<Object[]> rows=processData(stmt,axisContainsNull,axisValueSets,groupingSetsList);
    boolean sparse=setAxisDataAndDecideSparseUse(axisValueSets,axisContainsNull,groupingSetsList,rows);
    SegmentDataset[] nonGroupingDataSets=null;
    final Map<BitKey,SegmentDataset[]> groupingDataSetsMap=new HashMap<BitKey,SegmentDataset[]>();
    if (useGroupingSet) {
      populateDataSetMapOnGroupingColumnsBitKeys(groupingSetsList,sparse,groupingDataSetsMap);
    }
 else {
      nonGroupingDataSets=createDataSets(sparse,groupingSetsList.getDefaultSegments(),groupingSetsList.getDefaultAxes());
    }
    loadDataToDataSets(groupingSetsList,rows,groupingDataSetsMap,nonGroupingDataSets,axisContainsNull,sparse);
    setDataToSegments(groupingSetsList,nonGroupingDataSets,groupingDataSetsMap,pinnedSegments);
  }
 catch (  SQLException e) {
    throw stmt.handle(e);
  }
 finally {
    if (stmt != null) {
      stmt.close();
    }
    setFailOnStillLoadingSegments(groupingSetsList);
  }
}