Program: 51473
Project: 51473
Buggy source:
/** 
 * Reads a segment of <code>measure</code>, where <code>columns</code> are constrained to <code>values</code>.  Each entry in <code>values</code> can be null, meaning don't constrain, or can have several values. For example, <code>getSegment({Unit_sales}, {Region, State, Year}, {"West"}, {"CA", "OR", "WA"}, null})</code> returns sales in states CA, OR and WA in the Western region, for all years.
 * @pre segments[i].aggregation == aggregation
 */
static void load(final Segment[] segments,final BitKey levelBitKey,final BitKey measureBitKey,final Collection pinnedSegments,final Aggregation.Axis[] axes){
  String sql=AggregationManager.instance().generateSql(segments,levelBitKey,measureBitKey);
  Segment segment0=segments[0];
  RolapStar star=segment0.aggregation.getStar();
  RolapStar.Column[] columns=segment0.aggregation.getColumns();
  int arity=columns.length;
  ResultSet resultSet=null;
  final int measureCount=segments.length;
  java.sql.Connection jdbcConnection=star.getJdbcConnection();
  try {
    resultSet=RolapUtil.executeQuery(jdbcConnection,sql,"String_Node_Str");
    List rows=new ArrayList();
    while (resultSet.next()) {
      Object[] row=new Object[arity + measureCount];
      int k=1;
      for (int i=0; i < arity; i++) {
        Object o=resultSet.getObject(k++);
        if (o == null) {
          o=RolapUtil.sqlNullValue;
        }
        Integer offsetInteger=axes[i].getOffset(o);
        if (offsetInteger == null) {
          axes[i].addNextOffset(o);
        }
        row[i]=o;
      }
      for (int i=0; i < measureCount; i++) {
        Object o=resultSet.getObject(k++);
        if (o == null) {
          o=Util.nullValue;
        }
        row[arity + i]=o;
      }
      rows.add(row);
    }
    boolean sparse=false;
    int n=1;
    for (int i=0; i < arity; i++) {
      Aggregation.Axis axis=axes[i];
      int size=axis.loadKeys();
      int previous=n;
      n*=size;
      if ((n < previous) || (n < size)) {
        n=Integer.MAX_VALUE;
        sparse=true;
      }
    }
    sparse=sparse || useSparse((double)n,(double)rows.size());
    final SegmentDataset[] dataSets;
    final SparseSegmentDataset[] sparseDatasets;
    final DenseSegmentDataset[] denseDatasets;
    if (sparse) {
      sparseDatasets=new SparseSegmentDataset[segments.length];
      dataSets=sparseDatasets;
      denseDatasets=null;
    }
 else {
      denseDatasets=new DenseSegmentDataset[segments.length];
      dataSets=denseDatasets;
      sparseDatasets=null;
    }
    if (sparse) {
      for (int i=0; i < segments.length; i++) {
        sparseDatasets[i]=new SparseSegmentDataset(segments[i]);
      }
    }
 else {
      for (int i=0; i < segments.length; i++) {
        denseDatasets[i]=new DenseSegmentDataset(segments[i],new Object[n]);
      }
    }
    int[] pos=new int[arity];
    for (int i=0, count=rows.size(); i < count; i++) {
      Object[] row=(Object[])rows.get(i);
      int k=0;
      for (int j=0; j < arity; j++) {
        k*=axes[j].getKeys().length;
        Object o=row[j];
        Aggregation.Axis axis=axes[j];
        Integer offsetInteger=axis.getOffset(o);
        int offset=offsetInteger.intValue();
        pos[j]=offset;
        k+=offset;
      }
      CellKey key=null;
      if (sparse) {
        key=new CellKey((int[])pos.clone());
        for (int j=0; j < segments.length; j++) {
          final Object o=row[arity + j];
          sparseDatasets[j].put(key,o);
        }
      }
 else {
        for (int j=0; j < segments.length; j++) {
          final Object o=row[arity + j];
          denseDatasets[j].set(k,o);
        }
      }
    }
    for (int i=0; i < segments.length; i++) {
      segments[i].setData(dataSets[i],pinnedSegments);
    }
  }
 catch (  SQLException e) {
    throw Util.newInternal(e,"String_Node_Str" + sql + "String_Node_Str");
  }
 finally {
    try {
      if (resultSet != null) {
        resultSet.getStatement().close();
        resultSet.close();
      }
    }
 catch (    SQLException e) {
    }
    try {
      jdbcConnection.close();
    }
 catch (    SQLException e) {
    }
    for (int i=0; i < segments.length; i++) {
      segments[i].setFailed();
    }
  }
}

Fixed version (ground truth):
/** 
 * Reads a segment of <code>measure</code>, where <code>columns</code> are constrained to <code>values</code>.  Each entry in <code>values</code> can be null, meaning don't constrain, or can have several values. For example, <code>getSegment({Unit_sales}, {Region, State, Year}, {"West"}, {"CA", "OR", "WA"}, null})</code> returns sales in states CA, OR and WA in the Western region, for all years.
 * @pre segments[i].aggregation == aggregation
 */
static void load(final Segment[] segments,final BitKey levelBitKey,final BitKey measureBitKey,final Collection pinnedSegments,final Aggregation.Axis[] axes){
  String sql=AggregationManager.instance().generateSql(segments,levelBitKey,measureBitKey);
  Segment segment0=segments[0];
  RolapStar star=segment0.aggregation.getStar();
  RolapStar.Column[] columns=segment0.aggregation.getColumns();
  int arity=columns.length;
  ResultSet resultSet=null;
  final int measureCount=segments.length;
  java.sql.Connection jdbcConnection=star.getJdbcConnection();
  try {
    resultSet=RolapUtil.executeQuery(jdbcConnection,sql,"String_Node_Str");
    List rows=new ArrayList();
    while (resultSet.next()) {
      Object[] row=new Object[arity + measureCount];
      int k=1;
      for (int i=0; i < arity; i++) {
        Object o=resultSet.getObject(k++);
        if (o == null) {
          o=RolapUtil.sqlNullValue;
        }
        Integer offsetInteger=axes[i].getOffset(o);
        if (offsetInteger == null) {
          axes[i].addNextOffset(o);
        }
        row[i]=o;
      }
      for (int i=0; i < measureCount; i++) {
        Object o=resultSet.getObject(k++);
        if (o == null) {
          o=Util.nullValue;
        }
 else         if (segments[i].measure.isNumeric()) {
          if (o instanceof Double) {
          }
 else           if (o instanceof Number) {
            o=new Double(((Number)o).doubleValue());
          }
 else {
            double d=Double.parseDouble(o.toString());
            o=new Double(d);
          }
        }
        row[arity + i]=o;
      }
      rows.add(row);
    }
    boolean sparse=false;
    int n=1;
    for (int i=0; i < arity; i++) {
      Aggregation.Axis axis=axes[i];
      int size=axis.loadKeys();
      int previous=n;
      n*=size;
      if ((n < previous) || (n < size)) {
        n=Integer.MAX_VALUE;
        sparse=true;
      }
    }
    sparse=sparse || useSparse((double)n,(double)rows.size());
    final SegmentDataset[] dataSets;
    final SparseSegmentDataset[] sparseDatasets;
    final DenseSegmentDataset[] denseDatasets;
    if (sparse) {
      sparseDatasets=new SparseSegmentDataset[segments.length];
      dataSets=sparseDatasets;
      denseDatasets=null;
    }
 else {
      denseDatasets=new DenseSegmentDataset[segments.length];
      dataSets=denseDatasets;
      sparseDatasets=null;
    }
    if (sparse) {
      for (int i=0; i < segments.length; i++) {
        sparseDatasets[i]=new SparseSegmentDataset(segments[i]);
      }
    }
 else {
      for (int i=0; i < segments.length; i++) {
        denseDatasets[i]=new DenseSegmentDataset(segments[i],new Object[n]);
      }
    }
    int[] pos=new int[arity];
    for (int i=0, count=rows.size(); i < count; i++) {
      Object[] row=(Object[])rows.get(i);
      int k=0;
      for (int j=0; j < arity; j++) {
        k*=axes[j].getKeys().length;
        Object o=row[j];
        Aggregation.Axis axis=axes[j];
        Integer offsetInteger=axis.getOffset(o);
        int offset=offsetInteger.intValue();
        pos[j]=offset;
        k+=offset;
      }
      CellKey key=null;
      if (sparse) {
        key=new CellKey((int[])pos.clone());
        for (int j=0; j < segments.length; j++) {
          final Object o=row[arity + j];
          sparseDatasets[j].put(key,o);
        }
      }
 else {
        for (int j=0; j < segments.length; j++) {
          final Object o=row[arity + j];
          denseDatasets[j].set(k,o);
        }
      }
    }
    for (int i=0; i < segments.length; i++) {
      segments[i].setData(dataSets[i],pinnedSegments);
    }
  }
 catch (  SQLException e) {
    throw Util.newInternal(e,"String_Node_Str" + sql + "String_Node_Str");
  }
 finally {
    try {
      if (resultSet != null) {
        resultSet.getStatement().close();
        resultSet.close();
      }
    }
 catch (    SQLException e) {
    }
    try {
      jdbcConnection.close();
    }
 catch (    SQLException e) {
    }
    for (int i=0; i < segments.length; i++) {
      segments[i].setFailed();
    }
  }
}