Program: 112407
Project: 112407
Buggy source:
private void initGuidepostDepth() throws IOException, ClassNotFoundException, SQLException {
  if (guidePostPerRegionBytes != null || guidePostWidthBytes != null) {
    int guidepostPerRegion=0;
    long guidepostWidth=QueryServicesOptions.DEFAULT_STATS_GUIDEPOST_WIDTH_BYTES;
    if (guidePostPerRegionBytes != null) {
      guidepostPerRegion=PInteger.INSTANCE.getCodec().decodeInt(guidePostPerRegionBytes,0,SortOrder.getDefault());
    }
    if (guidePostWidthBytes != null) {
      guidepostWidth=PLong.INSTANCE.getCodec().decodeInt(guidePostWidthBytes,0,SortOrder.getDefault());
    }
    this.guidePostDepth=StatisticsUtil.getGuidePostDepth(guidepostPerRegion,guidepostWidth,env.getRegion().getTableDesc());
  }
 else {
    long guidepostWidth=-1;
    Table htable=null;
    try {
      htable=env.getConnection().getTable(SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES,env.getConfiguration()));
      Get get=new Get(ptableKey);
      get.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES);
      Result result=htable.get(get);
      if (!result.isEmpty()) {
        Cell cell=result.listCells().get(0);
        guidepostWidth=PLong.INSTANCE.getCodec().decodeLong(cell.getValueArray(),cell.getValueOffset(),SortOrder.getDefault());
      }
 else       if (!isViewIndexTable) {
        try (Connection conn=QueryUtil.getConnectionOnServer(env.getConfiguration())){
          PTable table=PhoenixRuntime.getTable(conn,tableName);
          if (table.getType() == PTableType.INDEX && table.getIndexType() == IndexType.GLOBAL) {
            PName parentName=table.getParentName();
            byte[] parentKey=SchemaUtil.getTableKeyFromFullName(parentName.getString());
            get=new Get(parentKey);
            get.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES);
            result=htable.get(get);
            if (!result.isEmpty()) {
              Cell cell=result.listCells().get(0);
              guidepostWidth=PLong.INSTANCE.getCodec().decodeLong(cell.getValueArray(),cell.getValueOffset(),SortOrder.getDefault());
            }
          }
        }
       }
    }
  finally {
      if (htable != null) {
        try {
          htable.close();
        }
 catch (        IOException e) {
          LOG.warn("String_Node_Str" + htable.getName(),e);
        }
      }
    }
    if (guidepostWidth >= 0) {
      this.guidePostDepth=guidepostWidth;
    }
 else {
      Configuration config=env.getConfiguration();
      this.guidePostDepth=StatisticsUtil.getGuidePostDepth(config.getInt(QueryServices.STATS_GUIDEPOST_PER_REGION_ATTRIB,QueryServicesOptions.DEFAULT_STATS_GUIDEPOST_PER_REGION),config.getLong(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB,QueryServicesOptions.DEFAULT_STATS_GUIDEPOST_WIDTH_BYTES),env.getRegion().getTableDesc());
    }
  }
}

Fixed version (ground truth):
private void initGuidepostDepth() throws IOException, ClassNotFoundException, SQLException {
  if (guidePostPerRegionBytes != null || guidePostWidthBytes != null) {
    int guidepostPerRegion=0;
    long guidepostWidth=QueryServicesOptions.DEFAULT_STATS_GUIDEPOST_WIDTH_BYTES;
    if (guidePostPerRegionBytes != null) {
      guidepostPerRegion=PInteger.INSTANCE.getCodec().decodeInt(guidePostPerRegionBytes,0,SortOrder.getDefault());
    }
    if (guidePostWidthBytes != null) {
      guidepostWidth=PLong.INSTANCE.getCodec().decodeInt(guidePostWidthBytes,0,SortOrder.getDefault());
    }
    this.guidePostDepth=StatisticsUtil.getGuidePostDepth(guidepostPerRegion,guidepostWidth,env.getRegion().getTableDescriptor());
  }
 else {
    long guidepostWidth=-1;
    Table htable=null;
    try {
      htable=env.getConnection().getTable(SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES,env.getConfiguration()));
      Get get=new Get(ptableKey);
      get.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES);
      Result result=htable.get(get);
      if (!result.isEmpty()) {
        Cell cell=result.listCells().get(0);
        guidepostWidth=PLong.INSTANCE.getCodec().decodeLong(cell.getValueArray(),cell.getValueOffset(),SortOrder.getDefault());
      }
 else       if (!isViewIndexTable) {
        try (Connection conn=QueryUtil.getConnectionOnServer(env.getConfiguration())){
          PTable table=PhoenixRuntime.getTable(conn,tableName);
          if (table.getType() == PTableType.INDEX && table.getIndexType() == IndexType.GLOBAL) {
            PName parentName=table.getParentName();
            byte[] parentKey=SchemaUtil.getTableKeyFromFullName(parentName.getString());
            get=new Get(parentKey);
            get.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,PhoenixDatabaseMetaData.GUIDE_POSTS_WIDTH_BYTES);
            result=htable.get(get);
            if (!result.isEmpty()) {
              Cell cell=result.listCells().get(0);
              guidepostWidth=PLong.INSTANCE.getCodec().decodeLong(cell.getValueArray(),cell.getValueOffset(),SortOrder.getDefault());
            }
          }
        }
       }
    }
  finally {
      if (htable != null) {
        try {
          htable.close();
        }
 catch (        IOException e) {
          LOG.warn("String_Node_Str" + htable.getName(),e);
        }
      }
    }
    if (guidepostWidth >= 0) {
      this.guidePostDepth=guidepostWidth;
    }
 else {
      Configuration config=env.getConfiguration();
      this.guidePostDepth=StatisticsUtil.getGuidePostDepth(config.getInt(QueryServices.STATS_GUIDEPOST_PER_REGION_ATTRIB,QueryServicesOptions.DEFAULT_STATS_GUIDEPOST_PER_REGION),config.getLong(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB,QueryServicesOptions.DEFAULT_STATS_GUIDEPOST_WIDTH_BYTES),env.getRegion().getTableDescriptor());
    }
  }
}