Buggy code:
Pattern p8 = Pattern . compile ( ".{1,50}www.{1,500}" ) ; String [ ] fileNames = new String [ ] { "webmd_fkids" } ; 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 ( ( 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" ) ) ) { helProPost ++ ; if ( ( helProMap . get ( nameToken ) ) == null ) { helProMap . put ( nameToken , 1 ) ; } else { 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 . entriesSortedByValues ( userMap ) ; br = new BufferedReader ( new FileReader ( ( ( "data//" + fileLog ) + ".csv" ) ) ) ; int userSize = sortedUserMap . size ( ) ; int top25 = userSize // 4 ; int mid50 = userSize - ( top25 * 2 ) ; HelPro = helProMap . size ( ) ; staffCount = staffMap . size ( ) ; staffCount = staffMap . size ( ) ; mid50 = userSize - top25 ; List < String > sortedUserList = new ArrayList < String > ( ) ; for ( Map . Entry < String , Integer > ent : sortedUserMap ) { sortedUserList . add ( ent . getKey ( ) ) ; } q1Post = q2Post = 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 ) { continue ; } nameToken = nameToken . substring ( 1 , ( ( nameToken . length ( ) ) - 1 ) ) ; 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 ) ; System . out . println ( helProMap ) ; if ( helProMap . containsKey ( nameToken ) ) { if ( ( check . contains ( "www" ) ) | ( check . contains ( "http" ) ) ) { q1Post ++ ; String check2 = "<seq2seq4repair_space>" ; String check3 = "<seq2seq4repair_space>" ; Matcher m8 = p8 . matcher ( check ) ; List < String > matchstring8 = new ArrayList < String > ( ) ;

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