Buggy code:
public class StatisticsBuilder { private DataHandleStatistics handle ; private volatile boolean interrupt ; public StatisticsBuilder ( DataHandleStatistics handle ) { } public StatisticsContingencyTable getContingencyTable ( int column1 , boolean orderFromDefinition1 , int column2 , boolean orderFromDefinition2 ) { } public StatisticsContingencyTable getContingencyTable ( int column1 , Hierarchy hierarchy1 , int column2 , Hierarchy hierarchy2 ) { } public StatisticsContingencyTable getContingencyTable ( int column1 , int column2 ) { } public StatisticsContingencyTable getContingencyTable ( int column1 , int size1 , boolean orderFromDefinition1 , int column2 , int size2 , boolean orderFromDefinition2 ) { } public StatisticsContingencyTable getContingencyTable ( int column1 , int size1 , Hierarchy hierarchy1 , int column2 , int size2 , Hierarchy hierarchy2 ) { } public StatisticsContingencyTable getContingencyTable ( int column1 , int size1 , int column2 , int size2 ) { } public String [ ] getDistinctValues ( int column ) { } public String [ ] getDistinctValuesOrdered ( int column ) { } public String [ ] getDistinctValuesOrdered ( int column , boolean orderFromDefinition ) { } public String [ ] getDistinctValuesOrdered ( int column , Hierarchy hierarchy ) { interrupt = false ; final String [ ] list = getDistinctValues ( column ) ; final String attribute = handle . getAttributeName ( column ) ; final DataType < ? > datatype = handle . getDataType ( attribute ) ; final int level = handle . getGeneralization ( attribute ) ; final String [ ] [ ] _hierarchy = ( hierarchy != null ) ? hierarchy . getHierarchy ( ) : null ; if ( ( _hierarchy == null ) || ( level == 0 ) ) { sort ( list , datatype , handle . getSuppressionString ( ) ) ; } else { final Map < String , Integer > order = new HashMap < String , Integer > ( ) ; int max = 0 ; Set < String > baseSet = new HashSet < String > ( ) ; DataType < ? > baseType = handle . getBaseDataType ( attribute ) ; for ( int i = 0 ; i < ( _hierarchy . length ) ; i ++ ) { String element = _hierarchy [ i ] [ 0 ] ; checkInterrupt ( ) ; if ( baseType . isValid ( element ) ) baseSet . add ( element ) ; } String [ ] baseArray = baseSet . toArray ( new String [ baseSet . size ( ) ] ) ; sort ( baseArray , handle . getBaseDataType ( attribute ) , handle . getSuppressionString ( ) ) ; Map < String , Integer > baseOrder = new HashMap < String , Integer > ( ) ; for ( int i = 0 ; i < ( baseArray . length ) ; i ++ ) { checkInterrupt ( ) ; baseOrder . put ( baseArray [ i ] , i ) ; } int lower = ( handle . isOptimized ( ) ) ? 1 : level ; <START_BUG> int upper = ( handle . isOptimized ( ) ) ? _hierarchy [ 0 ] . length : level ; <END_BUG> for ( int i = 0 ; i < ( _hierarchy . length ) ; i ++ ) { checkInterrupt ( ) ; for ( int j = lower ; j < upper ; j ++ ) { if ( ! ( order . containsKey ( _hierarchy [ i ] [ j ] ) ) ) { Integer position = baseOrder . get ( _hierarchy [ i ] [ 0 ] ) ; if ( position != null ) { order . put ( _hierarchy [ i ] [ j ] , position ) ; max = ( Math . max ( position , max ) ) + 1 ; } } } } String supp = handle . getSuppressionString ( ) ; if ( supp != null ) order . put ( supp , max ) ; sort ( list , order ) ; } return list ; } public StatisticsEquivalenceClasses getEquivalenceClassStatistics ( ) { } public StatisticsFrequencyDistribution getFrequencyDistribution ( int column ) { } public StatisticsFrequencyDistribution getFrequencyDistribution ( int column , boolean orderFromDefinition ) { } public StatisticsFrequencyDistribution getFrequencyDistribution ( int column , Hierarchy hierarchy ) { } public StatisticsBuilderInterruptible getInterruptibleInstance ( ) { } @ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public < T > Map < String , StatisticsSummary < ? > > getSummaryStatistics ( boolean listwiseDeletion ) { } private void checkInterrupt ( ) { } private Hierarchy getHierarchy ( int column , boolean orderFromDefinition ) { } private String [ ] getScaledValues ( String [ ] values , int length ) { } private < U , V > StatisticsSummaryOrdinal getSummaryStatisticsOrdinal ( final int generalization , final DataType < U > dataType , final DataType < V > baseDataType , final Hierarchy hierarchy ) { } private boolean isOutlier ( Group < TupleWrapper > element , String suppression ) { } private void sort ( final String [ ] array , final DataType < ? > type , final String suppressionString ) { } private void sort ( final String [ ] array , final Map < String , Integer > order ) { } @ SuppressWarnings ( { "unchecked" , "rawtypes" } ) private String toString ( DataType < ? > type , double value , boolean isPeriod , boolean isSquare ) { } @ SuppressWarnings ( "unchecked" ) private < T > T toValue ( DataType < T > type , double value ) { } void interrupt ( ) { } }

Fix:
int upper = ( handle . isOptimized ( ) ) ? _hierarchy [ 0 ] . length : level + 1 ;