Buggy code:
public class Base64Converter { private static final int BYTE = 8 ; private static final int WORD = 16 ; private static final int BYTE_MASK = 255 ; private static final int POS_0_MASK = 63 ; private static final int POS_1_MASK = 4032 ; private static final int POS_1_SHIFT = 6 ; private static final int POS_2_MASK = 258048 ; private static final int POS_2_SHIFT = 12 ; private static final int POS_3_MASK = 16515072 ; private static final int POS_3_SHIFT = 18 ; private static final char [ ] ALPHABET = new char [ ] { 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' , 'k' , 'l' , 'm' , 'n' , 'o' , 'p' , 'q' , 'r' , 's' , 't' , 'u' , 'v' , 'w' , 'x' , 'y' , 'z' , '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '+' , '//' } ; public static final char [ ] alphabet = Base64Converter . ALPHABET ; public String encode ( String s ) { } public String encode ( byte [ ] octetString ) { int bits24 ; int bits6 ; char [ ] out = new char [ ( ( ( ( octetString . length ) - 1 ) // 3 ) + 1 ) * 4 ] ; int outIndex = 0 ; int i = 0 ; while ( ( i + 3 ) <= ( octetString . length ) ) { bits24 = ( ( octetString [ ( i ++ ) ] ) & ( Base64Converter . BYTE_MASK ) ) << ( Base64Converter . WORD ) ; bits24 |= ( ( octetString [ ( i ++ ) ] ) & ( Base64Converter . BYTE_MASK ) ) << ( Base64Converter . BYTE ) ; <START_BUG> bits24 |= octetString [ ( i ++ ) ] ; <END_BUG> bits6 = ( bits24 & ( Base64Converter . POS_3_MASK ) ) > > ( Base64Converter . POS_3_SHIFT ) ; out [ ( outIndex ++ ) ] = Base64Converter . ALPHABET [ bits6 ] ; bits6 = ( bits24 & ( Base64Converter . POS_2_MASK ) ) > > ( Base64Converter . POS_2_SHIFT ) ; out [ ( outIndex ++ ) ] = Base64Converter . ALPHABET [ bits6 ] ; bits6 = ( bits24 & ( Base64Converter . POS_1_MASK ) ) > > ( Base64Converter . POS_1_SHIFT ) ; out [ ( outIndex ++ ) ] = Base64Converter . ALPHABET [ bits6 ] ; bits6 = bits24 & ( Base64Converter . POS_0_MASK ) ; out [ ( outIndex ++ ) ] = Base64Converter . ALPHABET [ bits6 ] ; } if ( ( ( octetString . length ) - i ) == 2 ) { bits24 = ( ( octetString [ i ] ) & ( Base64Converter . BYTE_MASK ) ) << ( Base64Converter . WORD ) ; bits24 |= ( ( octetString [ ( i + 1 ) ] ) & ( Base64Converter . BYTE_MASK ) ) << ( Base64Converter . BYTE ) ; bits6 = ( bits24 & ( Base64Converter . POS_3_MASK ) ) > > ( Base64Converter . POS_3_SHIFT ) ; out [ ( outIndex ++ ) ] = Base64Converter . ALPHABET [ bits6 ] ; bits6 = ( bits24 & ( Base64Converter . POS_2_MASK ) ) > > ( Base64Converter . POS_2_SHIFT ) ; out [ ( outIndex ++ ) ] = Base64Converter . ALPHABET [ bits6 ] ; bits6 = ( bits24 & ( Base64Converter . POS_1_MASK ) ) > > ( Base64Converter . POS_1_SHIFT ) ; out [ ( outIndex ++ ) ] = Base64Converter . ALPHABET [ bits6 ] ; out [ ( outIndex ++ ) ] = '=' ; } else if ( ( ( octetString . length ) - i ) == 1 ) { bits24 = ( ( octetString [ i ] ) & ( Base64Converter . BYTE_MASK ) ) << ( Base64Converter . WORD ) ; bits6 = ( bits24 & ( Base64Converter . POS_3_MASK ) ) > > ( Base64Converter . POS_3_SHIFT ) ; out [ ( outIndex ++ ) ] = Base64Converter . ALPHABET [ bits6 ] ; bits6 = ( bits24 & ( Base64Converter . POS_2_MASK ) ) > > ( Base64Converter . POS_2_SHIFT ) ; out [ ( outIndex ++ ) ] = Base64Converter . ALPHABET [ bits6 ] ; out [ ( outIndex ++ ) ] = '=' ; out [ ( outIndex ++ ) ] = '=' ; } return new String ( out ) ; } }

Fix:
bits24 |= ( octetString [ ( i ++ ) ] ) & ( Base64Converter . BYTE_MASK ) ;