Buggy code:
private int bsLive ; private final CRC crc = new CRC ( ) ; private int nInUse ; private int nMTF ; private int workDone ; private int workLimit ; private boolean firstAttempt ; private int currentChar = - 1 ; private int runLength = 0 ; private int blockCRC ; private int combinedCRC ; private int allowableBlockSize ; private BZip2CompressorOutputStream . Data data ; private OutputStream out ; public static int chooseBlockSize ( long inputLength ) { } public BZip2CompressorOutputStream ( final OutputStream out ) throws IOException { } public BZip2CompressorOutputStream ( final OutputStream out , final int blockSize ) throws IOException { } public void write ( final int b ) throws IOException { } private void writeRun ( ) throws IOException { } protected void finalize ( ) throws Throwable { } public void finish ( ) throws IOException { } public void close ( ) throws IOException { } public void flush ( ) throws IOException { } private void init ( ) throws IOException { } private void initBlock ( ) { } private void endBlock ( ) throws IOException { } private void endCompression ( ) throws IOException { } public final int getBlockSize ( ) { } public void write ( final byte [ ] buf , int offs , final int len ) throws IOException { } private void write0 ( int b ) throws IOException { } private static void hbAssignCodes ( final int [ ] code , final byte [ ] length , final int minLen , final int maxLen , final int alphaSize ) { } private void bsFinishedWithStream ( ) throws IOException { } private void bsW ( final int n , final int v ) throws IOException { } private void bsPutUByte ( final int c ) throws IOException { } private void bsPutInt ( final int u ) throws IOException { } private void sendMTFValues ( ) throws IOException { } private void sendMTFValues0 ( final int nGroups , final int alphaSize ) { } private int sendMTFValues1 ( final int nGroups , final int alphaSize ) { } private void sendMTFValues2 ( final int nGroups , final int nSelectors ) { } private void sendMTFValues3 ( final int nGroups , final int alphaSize ) { } private void sendMTFValues4 ( ) throws IOException { } private void sendMTFValues5 ( final int nGroups , final int nSelectors ) throws IOException { } private void sendMTFValues6 ( final int nGroups , final int alphaSize ) throws IOException { } private void sendMTFValues7 ( final int nSelectors ) throws IOException { } private void moveToFrontCodeAndSend ( ) throws IOException { } private boolean mainSimpleSort ( final BZip2CompressorOutputStream . Data dataShadow , final int lo , final int hi , final int d ) { } private static void vswap ( int [ ] fmap , int p1 , int p2 , int n ) { } private static byte med3 ( byte a , byte b , byte c ) { } private void blockSort ( ) { } private void mainQSort3 ( final BZip2CompressorOutputStream . Data dataShadow , final int loSt , final int hiSt , final int dSt ) { } private void mainSort ( ) { } private void randomiseBlock ( ) { final boolean [ ] inUse = this . data . inUse ; final byte [ ] block = this . data . block ; final int lastShadow = this . last ; for ( int i = 256 ; ( -- i ) >= 0 ; ) inUse [ i ] = false ; int rNToGo = 0 ; int rTPos = 0 ; for ( int i = 0 , j = 1 ; i <= lastShadow ; i = j , j ++ ) { if ( rNToGo == 0 ) { <START_BUG> rNToGo = ( ( char ) ( BZip2Constants . rNums [ rTPos ] ) ) ; <END_BUG> if ( ( ++ rTPos ) == 512 ) { rTPos = 0 ; } } rNToGo -- ; block [ j ] ^= ( rNToGo == 1 ) ? 1 : 0 ; inUse [ ( ( block [ j ] ) & 255 ) ] = true ; } this . blockRandomised = true ; } private void generateMTFValues ( ) { } private static final class Data extends Object { final boolean [ ] inUse = new boolean [ 256 ] ; final byte [ ] unseqToSeq = new byte [ 256 ] ; final int [ ] mtfFreq = new int [ MAX_ALPHA_SIZE ] ; final byte [ ] selector = new byte [ MAX_SELECTORS ] ; final byte [ ] selectorMtf = new byte [ MAX_SELECTORS ] ; final byte [ ] generateMTFValues_yy = new byte [ 256 ] ; final byte [ ] [ ] sendMTFValues_len = new byte [ N_GROUPS ] [ MAX_ALPHA_SIZE ] ; final int [ ] [ ] sendMTFValues_rfreq = new int [ N_GROUPS ] [ MAX_ALPHA_SIZE ] ; final int [ ] sendMTFValues_fave = new int [ N_GROUPS ] ; final short [ ] sendMTFValues_cost = new short [ N_GROUPS ] ; final int [ ] [ ] sendMTFValues_code = new int [ N_GROUPS ] [ MAX_ALPHA_SIZE ] ; final byte [ ] sendMTFValues2_pos = new byte [ N_GROUPS ] ; final boolean [ ] sentMTFValues4_inUse16 = new boolean [ 16 ] ; final int [ ] stack_ll = new int [ BZip2CompressorOutputStream . QSORT_STACK_SIZE ] ; final int [ ] stack_hh = new int [ BZip2CompressorOutputStream . QSORT_STACK_SIZE ] ; final int [ ] stack_dd = new int [ BZip2CompressorOutputStream . QSORT_STACK_SIZE ] ; final int [ ] mainSort_runningOrder = new int [ 256 ] ; final int [ ] mainSort_copy = new int [ 256 ] ; final boolean [ ] mainSort_bigDone = new boolean [ 256 ] ; final int [ ] heap = new int [ ( MAX_ALPHA_SIZE ) + 2 ] ;

Fix:
rNToGo = ( ( char ) ( Rand . rNums ( rTPos ) ) ) ;