Buggy code:
public class Nysiis implements StringEncoder { private static final char [ ] CHARS_A = new char [ ] { 'A' } ; private static final char [ ] CHARS_AF = new char [ ] { 'A' , 'F' } ; private static final char [ ] CHARS_C = new char [ ] { 'C' } ; private static final char [ ] CHARS_FF = new char [ ] { 'F' , 'F' } ; private static final char [ ] CHARS_G = new char [ ] { 'G' } ; private static final char [ ] CHARS_N = new char [ ] { 'N' } ; private static final char [ ] CHARS_NN = new char [ ] { 'N' , 'N' } ; private static final char [ ] CHARS_S = new char [ ] { 'S' } ; private static final char [ ] CHARS_SSS = new char [ ] { 'S' , 'S' , 'S' } ; private static final Pattern PAT_MAC = Pattern . compile ( "^MAC" ) ; private static final Pattern PAT_KN = Pattern . compile ( "^KN" ) ; private static final Pattern PAT_K = Pattern . compile ( "^K" ) ; private static final Pattern PAT_PH_PF = Pattern . compile ( "^(PH|PF)" ) ; private static final Pattern PAT_SCH = Pattern . compile ( "^SCH" ) ; private static final Pattern PAT_EE_IE = Pattern . compile ( "(EE|IE)$" ) ; private static final Pattern PAT_DT_ETC = Pattern . compile ( "(DT|RT|RD|NT|ND)$" ) ; private static final char SPACE = '<seq2seq4repair_space>' ; private static final int TRUE_LENGTH = 6 ; private static boolean isVowel ( final char c ) { } private static char [ ] transcodeRemaining ( final char prev , final char curr , final char next , final char aNext ) { } private final boolean strict ; public Nysiis ( ) { } public Nysiis ( final boolean strict ) { } @ Override public Object encode ( Object obj ) throws EncoderException { } @ Override public String encode ( String str ) { } public boolean isStrict ( ) { } public String nysiis ( String str ) { if ( str == null ) { return null ; } str = SoundexUtils . clean ( str ) ; if ( ( str . length ( ) ) == 0 ) { return str ; } str = Nysiis . PAT_MAC . matcher ( str ) . replaceFirst ( "MCC" ) ; str = Nysiis . PAT_KN . matcher ( str ) . replaceFirst ( "NN" ) ; str = Nysiis . PAT_K . matcher ( str ) . replaceFirst ( "C" ) ; str = Nysiis . PAT_PH_PF . matcher ( str ) . replaceFirst ( "FF" ) ; str = Nysiis . PAT_SCH . matcher ( str ) . replaceFirst ( "SSS" ) ; str = Nysiis . PAT_EE_IE . matcher ( str ) . replaceFirst ( "Y" ) ; str = Nysiis . PAT_DT_ETC . matcher ( str ) . replaceFirst ( "D" ) ; <START_BUG> StringBuffer key = new StringBuffer ( str . length ( ) ) ; <END_BUG> key . append ( str . charAt ( 0 ) ) ; final char [ ] chars = str . toCharArray ( ) ; final int len = chars . length ; for ( int i = 1 ; i < len ; i ++ ) { final char next = ( i < ( len - 1 ) ) ? chars [ ( i + 1 ) ] : Nysiis . SPACE ; final char aNext = ( i < ( len - 2 ) ) ? chars [ ( i + 2 ) ] : Nysiis . SPACE ; final char [ ] transcoded = Nysiis . transcodeRemaining ( chars [ ( i - 1 ) ] , chars [ i ] , next , aNext ) ; System . arraycopy ( transcoded , 0 , chars , i , transcoded . length ) ; if ( ( chars [ i ] ) != ( chars [ ( i - 1 ) ] ) ) { key . append ( chars [ i ] ) ; } } if ( ( key . length ( ) ) > 1 ) { char lastChar = key . charAt ( ( ( key . length ( ) ) - 1 ) ) ; if ( lastChar == 'S' ) { key . deleteCharAt ( ( ( key . length ( ) ) - 1 ) ) ; lastChar = key . charAt ( ( ( key . length ( ) ) - 1 ) ) ; } if ( ( key . length ( ) ) > 2 ) { final char last2Char = key . charAt ( ( ( key . length ( ) ) - 2 ) ) ; if ( ( last2Char == 'A' ) && ( lastChar == 'Y' ) ) { key . deleteCharAt ( ( ( key . length ( ) ) - 2 ) ) ; } } if ( lastChar == 'A' ) { key . deleteCharAt ( ( ( key . length ( ) ) - 1 ) ) ; } } final String string = key . toString ( ) ; return this . isStrict ( ) ? string . substring ( 0 , Math . min ( Nysiis . TRUE_LENGTH , string . length ( ) ) ) : string ; } }

Fix:
StringBuilder key = new StringBuilder ( str . length ( ) ) ;