Program: 112405
Project: 112405
Buggy source:
private RegionScanner rebuildIndices(final RegionScanner innerScanner,final Region region,final Scan scan,Configuration config) throws IOException {
  byte[] indexMetaData=scan.getAttribute(PhoenixIndexCodec.INDEX_PROTO_MD);
  boolean useProto=true;
  if (indexMetaData == null) {
    useProto=false;
    indexMetaData=scan.getAttribute(PhoenixIndexCodec.INDEX_MD);
  }
  boolean hasMore;
  int rowCount=0;
  try {
    int maxBatchSize=config.getInt(MUTATE_BATCH_SIZE_ATTRIB,QueryServicesOptions.DEFAULT_MUTATE_BATCH_SIZE);
    long maxBatchSizeBytes=config.getLong(MUTATE_BATCH_SIZE_BYTES_ATTRIB,QueryServicesOptions.DEFAULT_MUTATE_BATCH_SIZE_BYTES);
    MutationList mutations=new MutationList(maxBatchSize);
    region.startRegionOperation();
    byte[] uuidValue=ServerCacheClient.generateId();
synchronized (innerScanner) {
      do {
        List<Cell> results=new ArrayList<Cell>();
        hasMore=innerScanner.nextRaw(results);
        if (!results.isEmpty()) {
          Put put=null;
          Delete del=null;
          for (          Cell cell : results) {
            if (KeyValue.Type.codeToType(cell.getTypeByte()) == KeyValue.Type.Put) {
              if (put == null) {
                put=new Put(CellUtil.cloneRow(cell));
                put.setAttribute(useProto ? PhoenixIndexCodec.INDEX_PROTO_MD : PhoenixIndexCodec.INDEX_MD,indexMetaData);
                put.setAttribute(PhoenixIndexCodec.INDEX_UUID,uuidValue);
                put.setAttribute(REPLAY_WRITES,REPLAY_ONLY_INDEX_WRITES);
                mutations.add(put);
                put.setDurability(Durability.SKIP_WAL);
              }
              put.add(cell);
            }
 else {
              if (del == null) {
                del=new Delete(CellUtil.cloneRow(cell));
                del.setAttribute(useProto ? PhoenixIndexCodec.INDEX_PROTO_MD : PhoenixIndexCodec.INDEX_MD,indexMetaData);
                del.setAttribute(PhoenixIndexCodec.INDEX_UUID,uuidValue);
                del.setAttribute(REPLAY_WRITES,REPLAY_ONLY_INDEX_WRITES);
                mutations.add(del);
                del.setDurability(Durability.SKIP_WAL);
              }
              del.addDeleteMarker(cell);
            }
          }
          if (ServerUtil.readyToCommit(mutations.size(),mutations.byteSize(),maxBatchSize,maxBatchSizeBytes)) {
            region.batchMutate(mutations.toArray(new Mutation[mutations.size()]));
            uuidValue=ServerCacheClient.generateId();
            mutations.clear();
          }
          rowCount++;
        }
      }
 while (hasMore);
      if (!mutations.isEmpty()) {
        region.batchMutate(mutations.toArray(new Mutation[mutations.size()]));
      }
    }
  }
 catch (  IOException e) {
    logger.error("String_Node_Str" + Throwables.getStackTraceAsString(e));
    throw e;
  }
 finally {
    region.closeRegionOperation();
  }
  byte[] rowCountBytes=PLong.INSTANCE.toBytes(Long.valueOf(rowCount));
  final Cell aggKeyValue=PhoenixKeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY,SINGLE_COLUMN_FAMILY,SINGLE_COLUMN,AGG_TIMESTAMP,rowCountBytes,0,rowCountBytes.length);
  RegionScanner scanner=new BaseRegionScanner(innerScanner){
    @Override public HRegionInfo getRegionInfo(){
      return region.getRegionInfo();
    }
    @Override public boolean isFilterDone(){
      return true;
    }
    @Override public void close() throws IOException {
      innerScanner.close();
    }
    @Override public boolean next(    List<Cell> results) throws IOException {
      results.add(aggKeyValue);
      return false;
    }
    @Override public long getMaxResultSize(){
      return scan.getMaxResultSize();
    }
  }
;
  return scanner;
}

Fixed version (ground truth):
private RegionScanner rebuildIndices(final RegionScanner innerScanner,final Region region,final Scan scan,Configuration config) throws IOException {
  byte[] indexMetaData=scan.getAttribute(PhoenixIndexCodec.INDEX_PROTO_MD);
  boolean useProto=true;
  if (indexMetaData == null) {
    useProto=false;
    indexMetaData=scan.getAttribute(PhoenixIndexCodec.INDEX_MD);
  }
  boolean hasMore;
  int rowCount=0;
  try {
    int maxBatchSize=config.getInt(MUTATE_BATCH_SIZE_ATTRIB,QueryServicesOptions.DEFAULT_MUTATE_BATCH_SIZE);
    long maxBatchSizeBytes=config.getLong(MUTATE_BATCH_SIZE_BYTES_ATTRIB,QueryServicesOptions.DEFAULT_MUTATE_BATCH_SIZE_BYTES);
    MutationList mutations=new MutationList(maxBatchSize);
    region.startRegionOperation();
    byte[] uuidValue=ServerCacheClient.generateId();
synchronized (innerScanner) {
      do {
        List<Cell> results=new ArrayList<Cell>();
        hasMore=innerScanner.nextRaw(results);
        if (!results.isEmpty()) {
          Put put=null;
          Delete del=null;
          for (          Cell cell : results) {
            if (KeyValue.Type.codeToType(cell.getTypeByte()) == KeyValue.Type.Put) {
              if (put == null) {
                put=new Put(CellUtil.cloneRow(cell));
                put.setAttribute(useProto ? PhoenixIndexCodec.INDEX_PROTO_MD : PhoenixIndexCodec.INDEX_MD,indexMetaData);
                put.setAttribute(PhoenixIndexCodec.INDEX_UUID,uuidValue);
                put.setAttribute(REPLAY_WRITES,REPLAY_ONLY_INDEX_WRITES);
                mutations.add(put);
                put.setDurability(Durability.SKIP_WAL);
              }
              put.add(cell);
            }
 else {
              if (del == null) {
                del=new Delete(CellUtil.cloneRow(cell));
                del.setAttribute(useProto ? PhoenixIndexCodec.INDEX_PROTO_MD : PhoenixIndexCodec.INDEX_MD,indexMetaData);
                del.setAttribute(PhoenixIndexCodec.INDEX_UUID,uuidValue);
                del.setAttribute(REPLAY_WRITES,REPLAY_ONLY_INDEX_WRITES);
                mutations.add(del);
                del.setDurability(Durability.SKIP_WAL);
              }
              del.addDeleteMarker(cell);
            }
          }
          if (ServerUtil.readyToCommit(mutations.size(),mutations.byteSize(),maxBatchSize,maxBatchSizeBytes)) {
            region.batchMutate(mutations.toArray(new Mutation[mutations.size()]));
            uuidValue=ServerCacheClient.generateId();
            mutations.clear();
          }
          rowCount++;
        }
      }
 while (hasMore);
      if (!mutations.isEmpty()) {
        region.batchMutate(mutations.toArray(new Mutation[mutations.size()]));
      }
    }
  }
 catch (  IOException e) {
    logger.error("String_Node_Str" + Throwables.getStackTraceAsString(e));
    throw e;
  }
 finally {
    region.closeRegionOperation();
  }
  byte[] rowCountBytes=PLong.INSTANCE.toBytes(Long.valueOf(rowCount));
  final Cell aggKeyValue=PhoenixKeyValueUtil.newKeyValue(UNGROUPED_AGG_ROW_KEY,SINGLE_COLUMN_FAMILY,SINGLE_COLUMN,AGG_TIMESTAMP,rowCountBytes,0,rowCountBytes.length);
  RegionScanner scanner=new BaseRegionScanner(innerScanner){
    @Override public RegionInfo getRegionInfo(){
      return region.getRegionInfo();
    }
    @Override public boolean isFilterDone(){
      return true;
    }
    @Override public void close() throws IOException {
      innerScanner.close();
    }
    @Override public boolean next(    List<Cell> results) throws IOException {
      results.add(aggKeyValue);
      return false;
    }
    @Override public long getMaxResultSize(){
      return scan.getMaxResultSize();
    }
  }
;
  return scanner;
}