Buggy code:
Pattern p8 = Pattern . compile ( ".{1,50}www.{1,500}|.{1,50}http.{1,500}" ) ; String [ ] fileNames = new String [ ] { "webmd_addiction" } ; for ( String fileLog : fileNames ) { int HelPro = 0 ; int staffCount = 0 ; int q1Post = 0 ; int q2Post = 0 ; int q3Post = 0 ; int staffPost = 0 ; int helProPost = 0 ; hashmap = new HashMap < String , Integer > ( ) ; hashmap1 = new HashMap < String , Integer > ( ) ; userMap = new HashMap < String , Integer > ( ) ; helProMap = new HashMap < String , Integer > ( ) ; staffMap = new HashMap < String , Integer > ( ) ; uniqueSet = new ArrayList < String > ( ) ; BufferedReader br = new BufferedReader ( new FileReader ( ( ( "data//" + fileLog ) + ".csv" ) ) ) ; List < String > qidArray = new ArrayList < String > ( ) ; BufferedReader in = new BufferedReader ( new FileReader ( ( ( "data//" + fileLog ) + "_staff_qid.csv" ) ) ) ; BufferedWriter writer = new BufferedWriter ( new FileWriter ( ( ( "test//" + fileLog ) + "_PU.txt" ) ) ) ; String s = in . readLine ( ) ; while ( ( s = in . readLine ( ) ) != null ) { qidArray . add ( s ) ; } while ( br . ready ( ) ) { String check = br . readLine ( ) ; String [ ] tokenizedTerms1 = check . split ( "\"" ) ; String [ ] tokenizedTerms = check . split ( "," ) ; String token = tokenizedTerms [ 1 ] ; String nameToken = tokenizedTerms1 [ 3 ] ; if ( ( nameToken . length ( ) ) > 3 ) { if ( ( nameToken . charAt ( ( ( nameToken . length ( ) ) - 1 ) ) ) == '<seq2seq4repair_space>' ) { nameToken = nameToken . substring ( 0 , ( ( nameToken . length ( ) ) - 1 ) ) ; } } if ( ( check . contains ( "http" ) ) || ( check . contains ( "www" ) ) ) { if ( ( ( ( ( ( ( ( ( ( ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>MSN" ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>RNP" ) ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>CDOE" ) ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>MD" ) ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>MPH" ) ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>PHD" ) ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>PT" ) ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>DSc" ) ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>NCS" ) ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>MSCS" ) ) ) || ( nameToken . toUpperCase ( ) . contains ( ",<seq2seq4repair_space>RN" ) ) ) { System . out . println ( ( "HP<seq2seq4repair_space>-><seq2seq4repair_space>" + nameToken ) ) ; helProPost ++ ; if ( ( helProMap . get ( nameToken ) ) == null ) { System . out . println ( "+1" ) ; helProMap . put ( nameToken , 1 ) ; } else { System . out . println ( "+0" ) ; helProMap . put ( nameToken , ( ( helProMap . get ( nameToken ) ) + 1 ) ) ; } continue ; } if ( nameToken . contains ( "WebMD_Staff" ) ) { staffPost ++ ; if ( ( staffMap . get ( nameToken ) ) == null ) { staffMap . put ( nameToken , 1 ) ; } else { staffMap . put ( nameToken , ( ( staffMap . get ( nameToken ) ) + 1 ) ) ; } continue ; } if ( ( userMap . get ( nameToken ) ) == null ) { userMap . put ( nameToken , 1 ) ; } else { userMap . put ( nameToken , ( ( userMap . get ( nameToken ) ) + 1 ) ) ; } } } br . close ( ) ; SortedSet < Map . Entry < String , Integer > > sortedUserMap = WebMDURLExtractor_Count . entriesSortedByValues ( userMap ) ; br = new BufferedReader ( new FileReader ( ( ( "data//" + fileLog ) + ".csv" ) ) ) ; int userSize = sortedUserMap . size ( ) ; int top25 = userSize // 4 ; int mid50 = userSize - top25 ; HelPro = helProMap . size ( ) ; staffCount = staffMap . size ( ) ; List < String > sortedUserList = new ArrayList < String > ( ) ; for ( Map . Entry < String , Integer > ent : sortedUserMap ) { sortedUserList . add ( ent . getKey ( ) ) ; } q1Post = 0 ; q2Post = 0 ; q3Post = 0 ; while ( br . ready ( ) ) { String check = br . readLine ( ) ; String [ ] tokenizedTerms = check . split ( "\"" ) ; String token = tokenizedTerms [ 1 ] ; String nameToken = tokenizedTerms [ 3 ] ; if ( ( nameToken . length ( ) ) > 3 ) { if ( ( nameToken . charAt ( ( ( nameToken . length ( ) ) - 1 ) ) ) == '<seq2seq4repair_space>' ) { <START_BUG> nameToken = nameToken . replace ( nameToken . substring ( ( ( nameToken . length ( ) ) - 1 ) ) , "" ) ; <END_BUG> } } int selectedUserIndex = sortedUserList . indexOf ( nameToken ) ; if ( ( ( selectedUserIndex < mid50 ) && ( selectedUserIndex <= top25 ) ) && ( selectedUserIndex != ( - 1 ) ) ) { if ( ( check . contains ( "www" ) ) || ( check . contains ( "http" ) ) ) { q1Post ++ ; String check2 = "<seq2seq4repair_space>" ;

Fix:
nameToken = nameToken . substring ( 0 , ( ( nameToken . length ( ) ) - 1 ) ) ;