Buggy code:
@ SuppressWarnings ( "unchecked" ) Map < String , Object > fset = ( ( HashMap < String , Object > ) ( response . get ( "fset" ) ) ) ; String cfg = ( ( String ) ( response . get ( "config" ) ) ) ; @ SuppressWarnings ( "unchecked" ) HashMap < String , Object > tokenmap = ( ( HashMap < String , Object > ) ( response . get ( "tokenmap" ) ) ) ; String layer = ( ( String ) ( response . get ( "layer" ) ) ) ; List < HashMap < String , Object > > features = ( ( ArrayList < HashMap < String , Object > > ) ( fset . get ( "features" ) ) ) ; ObjectMapper om = new ObjectMapper ( ) ; String lyrHeader = ( ( String ) ( response . get ( "lyrheader" ) ) ) ; if ( ! ( lyrHeader . isEmpty ( ) ) ) { lyrHeader = ( "<b>" + lyrHeader ) + "<//b>" ; } String items = "" ; items += ( "<b>" + ( layer . toUpperCase ( ) ) ) + ":<seq2seq4repair_space><//b>" ; Boolean usingDist = ( ( Boolean ) ( response . get ( "calcdist" ) ) ) ; Boolean sortByDist = ( ( Boolean ) ( response . get ( "sortbydist" ) ) ) ; String distUnits = ( ( String ) ( response . get ( "distunits" ) ) ) ; String distToken = ( ( String ) ( response . get ( "disttoken" ) ) ) ; Map < String , Object > srmap = ( ( HashMap < String , Object > ) ( fset . get ( "spatialReference" ) ) ) ; Integer wkid = ( ( Integer ) ( srmap . get ( "wkid" ) ) ) ; SpatialReference fsetSr = SpatialReference . create ( wkid ) ; for ( int i = 0 ; i < ( features . size ( ) ) ; ++ i ) { HashMap < String , Object > f = features . get ( i ) ; Map < String , Object > att = ( ( Map < String , Object > ) ( f . get ( "attributes" ) ) ) ; Map < String , Object > objGeo = ( ( Map < String , Object > ) ( f . get ( "geometry" ) ) ) ; Set < String > fields = tokenmap . keySet ( ) ; Iterator < String > itFields = fields . iterator ( ) ; String item = cfg ; Double distVal = null ; if ( usingDist ) { String d = this . GetDistAsString ( objGeo , fsetSr , distUnits ) ; if ( sortByDist ) { distVal = Double . valueOf ( d ) ; } item = item . replace ( distToken , d ) ; } String attVal = null ; String sortAttVal = null ; while ( itFields . hasNext ( ) ) { String fldname = itFields . next ( ) ; String token = ( ( String ) ( tokenmap . get ( fldname ) ) ) ; attVal = att . get ( fldname ) . toString ( ) ; if ( ! sortByDist ) { if ( fldname . equals ( sortField ) ) { sortAttVal = attVal ; } } item = item . replace ( token , attVal ) ; } if ( ! sortByDist ) { if ( ! ( nameSortMap . containsKey ( sortAttVal ) ) ) { List < String > l = new ArrayList < String > ( ) ; l . add ( item ) ; nameSortMap . put ( sortAttVal , l ) ; nSortList . add ( sortAttVal ) ; } else { <START_BUG> List < String > l = nameSortMap . get ( attVal ) ; <END_BUG> l . add ( item ) ; Collections . sort ( l ) ; } } else { if ( ! ( distSortMap . containsKey ( distVal ) ) ) { List < String > l = new ArrayList < String > ( ) ; l . add ( item ) ; distSortMap . put ( distVal , l ) ; dSortList . add ( distVal ) ; } else { List < String > l = distSortMap . get ( distVal ) ; l . add ( item ) ; Collections . sort ( l ) ; } } } String sortedItems = "" ; if ( ! sortByDist ) { Collections . sort ( nSortList ) ; sortedItems = ConstructSortedItemsByName ( nameSortMap , nSortList ) ; } else { Collections . sort ( dSortList ) ; sortedItems = ConstructSortedItemsByDistance ( distSortMap , dSortList ) ; } items = sortedItems ; body += ( lyrHeader + "<br>" ) + items ; } String content = "" ; try { InputStream is = this . getClass ( ) . getClassLoader ( ) . getResourceAsStream ( "ReportTemplate.html" ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( is ) ) ; String ln ; while ( ( ln = br . readLine ( ) ) != null ) { content += ln ; } if ( ! ( timestamp . isEmpty ( ) ) ) { String tsToken = "${timestamp.value}" ; title = title . replace ( tsToken , timestamp ) ; if ( ( header ) != null ) { header = header . replace ( tsToken , timestamp ) ; } body = body . replace ( tsToken , timestamp ) ; } content = content . replace ( "${TITLE}" , ( ( "<h1>" + ( title ) ) + "<//h1>" ) ) ; content = content . replace ( "${HEADING}" , ( ( "<h2>" + ( header ) ) + "<//h2>" ) ) ; content = content . replace ( "${BODY}"

Fix:
List < String > l = nameSortMap . get ( sortAttVal ) ;