Buggy code:
public void testNextLongExtremeValues ( ) { } public void testNextInt ( ) { } public void testNextLong ( ) { } public void testNextSecureLong ( ) { } public void testNextSecureInt ( ) { } public void testNextPoisson ( ) { } public void testNextPoissonConsistency ( ) throws Exception { } public void checkNextPoissonConsistency ( double mean ) throws Exception { final int sampleSize = 1000 ; final int minExpectedCount = 7 ; long maxObservedValue = 0 ; final double alpha = 0.001 ; Frequency frequency = new Frequency ( ) ; for ( int i = 0 ; i < sampleSize ; i ++ ) { long value = randomData . nextPoisson ( mean ) ; if ( value > maxObservedValue ) { maxObservedValue = value ; } frequency . addValue ( value ) ; } PoissonDistribution poissonDistribution = new PoissonDistributionImpl ( mean ) ; int lower = 1 ; while ( ( ( poissonDistribution . cumulativeProbability ( ( lower - 1 ) ) ) * sampleSize ) < minExpectedCount ) { lower ++ ; } int upper = ( ( int ) ( 5 * mean ) ) ; while ( ( ( 1 - ( poissonDistribution . cumulativeProbability ( ( upper - 1 ) ) ) ) * sampleSize ) < minExpectedCount ) { upper -- ; } int binWidth = 1 ; boolean widthSufficient = false ; double lowerBinMass = 0 ; double upperBinMass = 0 ; while ( ! widthSufficient ) { lowerBinMass = poissonDistribution . cumulativeProbability ( lower , ( ( lower + binWidth ) - 1 ) ) ; upperBinMass = poissonDistribution . cumulativeProbability ( ( ( upper - binWidth ) + 1 ) , upper ) ; widthSufficient = ( ( FastMath . min ( lowerBinMass , upperBinMass ) ) * sampleSize ) >= minExpectedCount ; binWidth ++ ; } List < Integer > binBounds = new ArrayList < Integer > ( ) ; binBounds . add ( lower ) ; int bound = lower + binWidth ; while ( bound < ( upper - binWidth ) ) { binBounds . add ( bound ) ; bound += binWidth ; } binBounds . add ( bound ) ; binBounds . add ( upper ) ; final int binCount = ( binBounds . size ( ) ) + 1 ; long [ ] observed = new long [ binCount ] ; double [ ] expected = new double [ binCount ] ; observed [ 0 ] = 0 ; for ( int i = 0 ; i < lower ; i ++ ) { observed [ 0 ] += frequency . getCount ( i ) ; } expected [ 0 ] = ( poissonDistribution . cumulativeProbability ( ( lower - 1 ) ) ) * sampleSize ; observed [ ( binCount - 1 ) ] = 0 ; for ( int i = upper ; i <= maxObservedValue ; i ++ ) { observed [ ( binCount - 1 ) ] += frequency . getCount ( i ) ; } expected [ ( binCount - 1 ) ] = ( 1 - ( poissonDistribution . cumulativeProbability ( ( upper - 1 ) ) ) ) * sampleSize ; for ( int i = 1 ; i < ( binCount - 1 ) ; i ++ ) { observed [ i ] = 0 ; for ( int j = binBounds . get ( ( i - 1 ) ) ; j < ( binBounds . get ( i ) ) ; j ++ ) { observed [ i ] += frequency . getCount ( j ) ; } expected [ i ] = ( ( poissonDistribution . cumulativeProbability ( ( ( binBounds . get ( i ) ) - 1 ) ) ) - ( poissonDistribution . cumulativeProbability ( ( ( binBounds . get ( ( i - 1 ) ) ) - 1 ) ) ) ) * sampleSize ; } ChiSquareTest chiSquareTest = new ChiSquareTestImpl ( ) ; try { assertFalse ( chiSquareTest . chiSquareTest ( expected , observed , alpha ) ) ; } catch ( AssertionFailedError ex ) { <START_BUG> StringBuffer msgBuffer = new StringBuffer ( ) ; <END_BUG> DecimalFormat df = new DecimalFormat ( "#.##" ) ; msgBuffer . append ( "Chisquare<seq2seq4repair_space>test<seq2seq4repair_space>failed<seq2seq4repair_space>for<seq2seq4repair_space>mean<seq2seq4repair_space>=<seq2seq4repair_space>" ) ; msgBuffer . append ( mean ) ; msgBuffer . append ( "<seq2seq4repair_space>p-value<seq2seq4repair_space>=<seq2seq4repair_space>" ) ; msgBuffer . append ( chiSquareTest . chiSquareTest ( expected , observed ) ) ; msgBuffer . append ( "<seq2seq4repair_space>chisquare<seq2seq4repair_space>statistic<seq2seq4repair_space>=<seq2seq4repair_space>" ) ; msgBuffer . append ( chiSquareTest . chiSquare ( expected , observed ) ) ; msgBuffer . append ( ".<seq2seq4repair_space>\n" ) ; msgBuffer . append ( "bin\t\texpected\tobserved\n" ) ; for ( int i = 0 ; i < ( expected . length ) ; i ++ ) { msgBuffer . append ( "[" ) ; msgBuffer . append ( ( i == 0 ? 1 : binBounds . get ( ( i - 1 ) ) ) ) ; msgBuffer . append ( "," ) ; msgBuffer . append ( ( i == ( binBounds . size ( ) ) ? "inf" : binBounds . get ( i ) ) ) ; msgBuffer . append ( ")" ) ; msgBuffer . append ( "\t\t" ) ; msgBuffer . append ( df . format ( expected [ i ] ) ) ; msgBuffer . append ( "\t\t" ) ; msgBuffer . append ( observed [ i ] ) ; msgBuffer . append ( "\n" ) ; } msgBuffer . append ( "This<seq2seq4repair_space>test<seq2seq4repair_space>can<seq2seq4repair_space>fail<seq2seq4repair_space>randomly<seq2seq4repair_space>due<seq2seq4repair_space>to<seq2seq4repair_space>sampling<seq2seq4repair_space>error<seq2seq4repair_space>with<seq2seq4repair_space>probability<seq2seq4repair_space>" ) ; msgBuffer . append ( alpha ) ; msgBuffer . append ( "." ) ; fail ( msgBuffer . toString ( ) ) ; } } public void testNextHex ( ) { } public void testNextSecureHex ( ) { } public void testNextUniform ( ) { } public void testNextUniformExclusiveEndpoints ( ) { } public void testNextGaussian ( ) { } public void testNextExponential ( ) { } public void testConfig ( ) { }

Fix:
StringBuilder msgBuffer = new StringBuilder ( ) ;