Program: 112970
Project: 112970
Buggy source:
/** 
 * This method is responsible for translating a query into appropriate normalized and binned (if necessary) queries that can be used by the underlying index implementation. For example, for unbounded dimensions such as time, an incoming query of July 2012 to July 2013 may get translated into 2 binned queries representing the 2012 portion of the query and the 2013 portion, each normalized to millis from the beginning of the year.
 * @param numericData the incoming query into the index implementation, to be translated into normalized, binned queries
 * @param dimensionDefinitions the definition for the dimensions
 * @return normalized indexes
 */
public static BinnedNumericDataset[] applyBins(final MultiDimensionalNumericData numericData,final NumericDimensionDefinition[] dimensionDefinitions){
  if (dimensionDefinitions.length == 0) {
    return new BinnedNumericDataset[0];
  }
  final BinRange[][] binRangesPerDimension=new BinRange[dimensionDefinitions.length][];
  int numBinnedQueries=1;
  for (int d=0; d < dimensionDefinitions.length; d++) {
    binRangesPerDimension[d]=dimensionDefinitions[d].getNormalizedRanges(numericData.getDataPerDimension()[d]);
    numBinnedQueries*=binRangesPerDimension[d].length;
  }
  final BinnedNumericDataset[] binnedQueries=new BinnedNumericDataset[numBinnedQueries];
  for (int d=0; d < dimensionDefinitions.length; d++) {
    for (int b=0; b < binRangesPerDimension[d].length; b++) {
      for (int i=b; i < numBinnedQueries; i+=binRangesPerDimension[d].length) {
        final NumericData[] rangePerDimension;
        if (binnedQueries[i] == null) {
          rangePerDimension=new NumericRange[dimensionDefinitions.length];
          binnedQueries[i]=new BinnedNumericDataset(binRangesPerDimension[d][b].getBinId(),new BasicNumericDataset(rangePerDimension));
        }
 else {
          rangePerDimension=binnedQueries[i].getDataPerDimension();
          final byte[] combinedBinId=ByteArrayUtils.combineArrays(binnedQueries[i].getBinId(),binRangesPerDimension[d][b].getBinId());
          binnedQueries[i]=new BinnedNumericDataset(combinedBinId,new BasicNumericDataset(rangePerDimension));
        }
        rangePerDimension[d]=new NumericRange(binRangesPerDimension[d][b].getNormalizedMin(),binRangesPerDimension[d][b].getNormalizedMax());
      }
    }
  }
  return binnedQueries;
}

Fixed version (ground truth):
/** 
 * This method is responsible for translating a query into appropriate normalized and binned (if necessary) queries that can be used by the underlying index implementation. For example, for unbounded dimensions such as time, an incoming query of July 2012 to July 2013 may get translated into 2 binned queries representing the 2012 portion of the query and the 2013 portion, each normalized to millis from the beginning of the year.
 * @param numericData the incoming query into the index implementation, to be translated into normalized, binned queries
 * @param dimensionDefinitions the definition for the dimensions
 * @return normalized indexes
 */
public static BinnedNumericDataset[] applyBins(final MultiDimensionalNumericData numericData,final NumericDimensionDefinition[] dimensionDefinitions){
  if (dimensionDefinitions.length == 0) {
    return new BinnedNumericDataset[0];
  }
  final BinRange[][] binRangesPerDimension=new BinRange[dimensionDefinitions.length][];
  int numBinnedQueries=1;
  for (int d=0; d < dimensionDefinitions.length; d++) {
    binRangesPerDimension[d]=dimensionDefinitions[d].getNormalizedRanges(numericData.getDataPerDimension()[d]);
    numBinnedQueries*=binRangesPerDimension[d].length;
  }
  final BinnedNumericDataset[] binnedQueries=new BinnedNumericDataset[numBinnedQueries];
  for (int d=0; d < dimensionDefinitions.length; d++) {
    for (int b=0; b < binRangesPerDimension[d].length; b++) {
      for (int i=b; i < numBinnedQueries; i+=binRangesPerDimension[d].length) {
        final NumericData[] rangePerDimension;
        if (binnedQueries[i] == null) {
          rangePerDimension=new NumericRange[dimensionDefinitions.length];
          binnedQueries[i]=new BinnedNumericDataset(binRangesPerDimension[d][b].getBinId(),new BasicNumericDataset(rangePerDimension),binRangesPerDimension[d][b].isFullExtent());
        }
 else {
          rangePerDimension=binnedQueries[i].getDataPerDimension();
          final byte[] combinedBinId=ByteArrayUtils.combineArrays(binnedQueries[i].getBinId(),binRangesPerDimension[d][b].getBinId());
          binnedQueries[i]=new BinnedNumericDataset(combinedBinId,new BasicNumericDataset(rangePerDimension),binnedQueries[i].fullExtent|=binRangesPerDimension[d][b].isFullExtent());
        }
        rangePerDimension[d]=new NumericRange(binRangesPerDimension[d][b].getNormalizedMin(),binRangesPerDimension[d][b].getNormalizedMax());
      }
    }
  }
  return binnedQueries;
}