Buggy code:
public static void scheduleRangeShuffledFetches ( TaskSchedulerContext schedulerContext , MasterPlan masterPlan , Stage stage , DataChannel channel , int maxNum ) throws IOException { } public static void scheduleFetchesByRoundRobin ( Stage stage , Map < ? , Collection < FetchProto > > partitions , String tableName , int num ) { } @ VisibleForTesting public static class FetchGroupMeta { long totalVolume ; List < FetchImpl > fetchUrls ; public FetchGroupMeta ( long volume , FetchImpl fetchUrls ) { } public Repartitioner . FetchGroupMeta addFetche ( FetchImpl fetches ) { } public void increaseVolume ( long volume ) { } public long getVolume ( ) { } public List < FetchProto > getFetchProtos ( ) { } } public static void scheduleHashShuffledFetches ( TaskSchedulerContext schedulerContext , MasterPlan masterPlan , Stage stage , DataChannel channel , int maxNum ) throws IOException { } public static Pair < Long [ ] , Map < String , List < FetchProto > > [ ] > makeEvenDistributedFetchImpl ( Map < Integer , Repartitioner . FetchGroupMeta > partitions , String tableName , int num ) { } public static void scheduleFetchesByEvenDistributedVolumes ( Stage stage , Map < Integer , Repartitioner . FetchGroupMeta > partitions , String tableName , int num ) { } public static void scheduleScatteredHashShuffleFetches ( TaskSchedulerContext schedulerContext , Stage stage , Map < ExecutionBlockId , List < IntermediateEntry > > intermediates , String tableName ) { } public static List < List < FetchProto > > splitOrMergeIntermediates ( @ NotNull String fetchName , ExecutionBlockId ebId , List < IntermediateEntry > entries , long splitVolume , long pageSize ) { } public static List < URI > createFullURIs ( int maxUrlLength , FetchProto fetch ) { } public static List < URI > createSimpleURIs ( int maxUrlLength , FetchProto fetch ) { } private static String getRangeParam ( FetchProto proto ) { } public static List < URI > createFetchURL ( int maxUrlLength , FetchProto fetch , boolean includeParts ) { String scheme = "http:////" ; StringBuilder urlPrefix = new StringBuilder ( scheme ) ; ExecutionBlockId ebId = new ExecutionBlockId ( fetch . getExecutionBlockId ( ) ) ; urlPrefix . append ( fetch . getHost ( ) ) . append ( ":" ) . append ( fetch . getPort ( ) ) . append ( "//?" ) . append ( "qid=" ) . append ( ebId . getQueryId ( ) . toString ( ) ) . append ( "&sid=" ) . append ( ebId . getId ( ) ) . append ( "&p=" ) . append ( fetch . getPartitionId ( ) ) . append ( "&type=" ) ; if ( ( fetch . getType ( ) ) == ( HASH_SHUFFLE ) ) { urlPrefix . append ( "h" ) ; } else if ( ( fetch . getType ( ) ) == ( RANGE_SHUFFLE ) ) { urlPrefix . append ( "r" ) . append ( "&" ) . append ( Repartitioner . getRangeParam ( fetch ) ) ; } else if ( ( fetch . getType ( ) ) == ( SCATTERED_HASH_SHUFFLE ) ) { urlPrefix . append ( "s" ) ; } if ( ( fetch . getLength ( ) ) >= 0 ) { urlPrefix . append ( "&offset=" ) . append ( fetch . getOffset ( ) ) . append ( "&length=" ) . append ( fetch . getLength ( ) ) ; } List < URI > fetchURLs = new ArrayList < URI > ( ) ; if ( includeParts ) { if ( ( ( fetch . getType ( ) ) == ( HASH_SHUFFLE ) ) || ( ( fetch . getType ( ) ) == ( SCATTERED_HASH_SHUFFLE ) ) ) { fetchURLs . add ( URI . create ( urlPrefix . toString ( ) ) ) ; } else { urlPrefix . append ( "&ta=" ) ; List < String > taskIdsParams = new ArrayList < String > ( ) ; StringBuilder taskIdListBuilder = new StringBuilder ( ) ; final List < Integer > taskIds = fetch . getTaskIdList ( ) ; final List < Integer > attemptIds = fetch . getAttemptIdList ( ) ; final List < Pair < Integer , Integer > > taskAndAttemptIds = new ArrayList < > ( taskIds . size ( ) ) ; for ( int i = 0 ; i < ( taskIds . size ( ) ) ; i ++ ) { taskAndAttemptIds . add ( new Pair ( taskIds . get ( i ) , attemptIds . get ( i ) ) ) ; } <START_BUG> taskAndAttemptIds . sort ( new Comparator < Pair < Integer , Integer > > ( ) { <END_BUG> @ Override public int compare ( Pair < Integer , Integer > p1 , Pair < Integer , Integer > p2 ) { return ( p1 . getFirst ( ) ) - ( p2 . getFirst ( ) ) ; } } ) ; boolean first = true ; for ( int i = 0 ; i < ( taskAndAttemptIds . size ( ) ) ; i ++ ) { StringBuilder taskAttemptId = new StringBuilder ( ) ; if ( ! first ) { taskAttemptId . append ( "," ) ; } else { first = false ; } int taskId = taskAndAttemptIds . get ( i ) . getFirst ( ) ; if ( taskId < 0 ) { continue ; } int attemptId = taskAndAttemptIds . get ( i ) . getSecond ( ) ; taskAttemptId . append ( taskId ) . append ( "_" ) . append ( attemptId ) ; if ( ( ( urlPrefix . length ( ) ) + ( taskIdListBuilder . length ( ) ) ) > maxUrlLength ) { taskIdsParams . add ( taskIdListBuilder . toString ( ) ) ; taskIdListBuilder = new StringBuilder ( ( ( taskId + "_" ) + attemptId ) ) ; } else { taskIdListBuilder . append ( taskAttemptId ) ; }

Fix:
Collections . sort ( taskAndAttemptIds , new Comparator < Pair < Integer , Integer > > ( ) {