Buggy code:
public class PratilipiContentUtil { private static final Logger logger = Logger . getLogger ( PratilipiContentUtil . class . getName ( ) ) ; private static final Gson gson = new GsonBuilder ( ) . create ( ) ; private static final String pageBreak = "<div<seq2seq4repair_space>style=\"page-break-after:always\"><//div>" ; private static final Pattern pageBreakPattern = Pattern . compile ( ( "<div<seq2seq4repair_space>style=\"page-break-after:always\"><//div>" + ( ( ( "|" + "<div\\s+style=\"page-break-(before|after).+?>(.+?)<//div>" ) + "|" ) + "<hr\\s+style=\"page-break-(before|after).+?>" ) ) ) ; private static final Pattern titlePattern = Pattern . compile ( ( "<h1.*?>(<.+?>)*(?<title>.+?)(<//.+?>)*<//h1>" + ( "|" + "<h2.*?>(<.+?>)*(?<subTitle>.+?)(<//.+?>)*<//h2>" ) ) ) ; private String content ; private Matcher matcher ; public PratilipiContentUtil ( String content ) { } public int getPageCount ( ) { } public String getContent ( int pageNo ) { } public String updateContent ( int pageNo , String pageContent ) { } public String updateContent ( int pageNo , String pageContent , boolean insertNew ) { } public String generateIndex ( ) { PratilipiContentUtil . logger . log ( Level . INFO , ( "Content<seq2seq4repair_space>length:<seq2seq4repair_space>" + ( content . length ( ) ) ) ) ; matcher . reset ( ) ; int pageCount = 0 ; int startIndex = 0 ; int endIndex = 0 ; JsonArray index = new JsonArray ( ) ; while ( endIndex < ( content . length ( ) ) ) { pageCount ++ ; startIndex = endIndex ; String pageContent ; if ( matcher . find ( ) ) { endIndex = matcher . end ( ) ; pageContent = content . substring ( startIndex , matcher . start ( ) ) ; } else { endIndex = content . length ( ) ; pageContent = content . substring ( startIndex ) ; } PratilipiContentUtil . logger . log ( Level . INFO , ( ( ( ( ( ( ( ( ( "Page<seq2seq4repair_space>" + pageCount ) + "<seq2seq4repair_space>length:<seq2seq4repair_space>" ) + ( endIndex - startIndex ) ) + "<seq2seq4repair_space>(" ) + startIndex ) + "<seq2seq4repair_space>-<seq2seq4repair_space>" ) + endIndex ) + ")<seq2seq4repair_space>" ) + ( endIndex == ( content . length ( ) ) ? "" : matcher . group ( ) ) ) ) ; Matcher titleMatcher = PratilipiContentUtil . titlePattern . matcher ( pageContent ) ; while ( titleMatcher . find ( ) ) { PratilipiContentUtil . logger . log ( Level . INFO , titleMatcher . group ( ) ) ; String title = titleMatcher . group ( "title" ) ; String subTitle = titleMatcher . group ( "subTitle" ) ; <START_BUG> if ( ( title != null ) && ( ! ( ( title = title . replaceAll ( "&nbsp;" , "<seq2seq4repair_space>" ) . trim ( ) ) . isEmpty ( ) ) ) ) { <END_BUG> PratilipiContentUtil . logger . log ( Level . INFO , ( "Title<seq2seq4repair_space>Found:<seq2seq4repair_space>" + title ) ) ; JsonObject indexItem = new JsonObject ( ) ; indexItem . addProperty ( "title" , title ) ; indexItem . addProperty ( "pageNo" , pageCount ) ; indexItem . addProperty ( "level" , 0 ) ; index . add ( indexItem ) ; } else if ( ( subTitle != null ) && ( ! ( ( subTitle = subTitle . replaceAll ( "&nbsp;" , "<seq2seq4repair_space>" ) . trim ( ) ) . isEmpty ( ) ) ) ) { PratilipiContentUtil . logger . log ( Level . INFO , ( "Sub-Title<seq2seq4repair_space>Found:<seq2seq4repair_space>" + subTitle ) ) ; JsonObject indexItem = new JsonObject ( ) ; indexItem . addProperty ( "title" , subTitle ) ; indexItem . addProperty ( "pageNo" , pageCount ) ; indexItem . addProperty ( "level" , 1 ) ; index . add ( indexItem ) ; } } } return PratilipiContentUtil . gson . toJson ( index ) ; } }

Fix:
if ( ( title != null ) && ( ! ( ( title = title . replaceAll ( "&nbsp;|<[//]?strong>" , "<seq2seq4repair_space>" ) . trim ( ) ) . isEmpty ( ) ) ) ) {