Buggy code:
public class ReferenceListBuilder { private PDFPaper pdfPaper ; public Set < Reference > references = new HashSet < Reference > ( ) ; private static final String period = "." ; private static final String comma = ",<seq2seq4repair_space>" ; private static final String and = "and<seq2seq4repair_space>" ; private static final String commaAnd = ( ReferenceListBuilder . comma ) + ( ReferenceListBuilder . and ) ; private static final Pattern REF_PATTERN = Pattern . compile ( "^(\\[\\d+\\]).*" ) ; private static final String AUTHOR_LENIENT_REG_EX = ( ( ( ( ( ( "^((([^.:,]*?<seq2seq4repair_space>){0,3}[^.:,]{2,}?)(" + ( ReferenceListBuilder . comma ) ) + "|" ) + ( ReferenceListBuilder . commaAnd ) ) + "|<seq2seq4repair_space>" ) + ( ReferenceListBuilder . and ) ) + ( Pattern . quote ( ReferenceListBuilder . period ) ) ) + "))+" ; private static final Pattern AUTHOR_LENIENT_PATTERN = Pattern . compile ( ReferenceListBuilder . AUTHOR_LENIENT_REG_EX ) ; private static final String AUTHOR_REG_EX = "^(((\\p{Lu}\\.<seq2seq4repair_space>)|(\\p{L}+[\\p{L}ǎ´\'`’-]*?\\p{Ll}<seq2seq4repair_space>)){1,3}\\p{Lu}[\\p{L}ǎ´\'`’-]*\\p{Ll}).*" ; private static final Pattern AUTHOR_PATTERN = Pattern . compile ( ReferenceListBuilder . AUTHOR_REG_EX ) ; public ReferenceListBuilder ( PDFPaper pdfPaper ) { } enum ReferenceFindingState { NONE , NEW_REF_TAG , REF_TAG_FOUND ; } public void locateReferences ( ) { } private Reference createReferenceEntry ( String referenceEntry ) { } static void addAuthors ( String referenceEntry , Reference reference ) { } private static Set < String > extractAuthors ( String referenceEntry ) { } static void extractAuthors ( String referenceEntry , Set < String > authors ) { } static void extractAuthors ( String referenceEntry , Set < String > authors , int recursionDepth ) { if ( recursionDepth > 15 ) { return ; } if ( ( StringUtils . isEmpty ( referenceEntry ) ) || ( StringUtils . isBlank ( referenceEntry ) ) ) { return ; } referenceEntry = referenceEntry . trim ( ) ; referenceEntry = referenceEntry . replace ( "--" , "<seq2seq4repair_space>" ) ; boolean lastEntry = false ; if ( referenceEntry . startsWith ( ReferenceListBuilder . period ) ) return ; else if ( referenceEntry . startsWith ( ReferenceListBuilder . commaAnd ) ) { referenceEntry = referenceEntry . replaceFirst ( ReferenceListBuilder . commaAnd , "" ) ; lastEntry = true ; } else if ( referenceEntry . startsWith ( ReferenceListBuilder . and ) ) { referenceEntry = referenceEntry . replaceFirst ( ReferenceListBuilder . and , "" ) ; lastEntry = true ; } else if ( referenceEntry . startsWith ( ReferenceListBuilder . comma ) ) { referenceEntry = referenceEntry . replaceFirst ( ReferenceListBuilder . comma , "" ) ; } Matcher lenientMatcher = ReferenceListBuilder . AUTHOR_LENIENT_PATTERN . matcher ( referenceEntry ) ; Matcher authorMatcher = ReferenceListBuilder . AUTHOR_PATTERN . matcher ( referenceEntry ) ; boolean authorMatcherFound = authorMatcher . find ( ) ; boolean lenientMatcherFound = lenientMatcher . find ( ) ; String author ; if ( authorMatcherFound ) { author = authorMatcher . group ( 1 ) ; } else if ( ( ! authorMatcherFound ) && lenientMatcherFound ) { author = lenientMatcher . group ( 2 ) ; } else { return ; } authors . add ( author ) ; <START_BUG> referenceEntry = referenceEntry . replaceFirst ( Pattern . quote ( author ) , "" ) ; <END_BUG> if ( ! lastEntry ) { ReferenceListBuilder . extractAuthors ( referenceEntry , authors , ( recursionDepth ++ ) ) ; } } private void addYear ( String referenceEntry , Reference reference ) { } }

Fix:
referenceEntry = referenceEntry . replaceFirst ( author , "" ) ;