Buggy code:
private final RemoteTaskFactory remoteTaskFactory ; private final Session session ; private final int splitBatchSize ; private final int initialHashPartitions ; private final StateMachine < StageState > stageState ; private final LinkedBlockingQueue < Throwable > failureCauses = new LinkedBlockingQueue < > ( ) ; private final Set < PlanNodeId > completeSources = new HashSet < > ( ) ; @ GuardedBy ( "this" ) private OutputBuffers currentOutputBuffers = OutputBuffers . INITIAL_EMPTY_OUTPUT_BUFFERS ; @ GuardedBy ( "this" ) private OutputBuffers nextOutputBuffers ; private final ExecutorService executor ; private final AtomicReference < DateTime > schedulingComplete = new AtomicReference < > ( ) ; private final Distribution getSplitDistribution = new Distribution ( ) ; private final Distribution scheduleTaskDistribution = new Distribution ( ) ; private final Distribution addSplitDistribution = new Distribution ( ) ; private final NodeSelector nodeSelector ; private final NodeTaskMap nodeTaskMap ; private final AtomicReference < Multimap < PlanNodeId , URI > > exchangeLocations = new AtomicReference ( ImmutableMultimap . < PlanNodeId , URI > of ( ) ) ; public SqlStageExecution ( QueryId queryId , LocationFactory locationFactory , StageExecutionPlan plan , NodeScheduler nodeScheduler , RemoteTaskFactory remoteTaskFactory , Session session , int splitBatchSize , int initialHashPartitions , ExecutorService executor , NodeTaskMap nodeTaskMap , OutputBuffers nextOutputBuffers ) { } private SqlStageExecution ( @ Nullable StageExecutionNode parent , QueryId queryId , AtomicInteger nextStageId , LocationFactory locationFactory , StageExecutionPlan plan , NodeScheduler nodeScheduler , RemoteTaskFactory remoteTaskFactory , Session session , int splitBatchSize , int initialHashPartitions , ExecutorService executor , NodeTaskMap nodeTaskMap ) { } @ Override public void cancelStage ( StageId stageId ) { } @ Override @ VisibleForTesting public StageState getState ( ) { } @ Override public StageInfo getStageInfo ( ) { } @ Override public synchronized void parentTasksAdded ( List < TaskId > parentTasks , boolean noMoreParentNodes ) { } public synchronized OutputBuffers getCurrentOutputBuffers ( ) { } public synchronized OutputBuffers updateToNextOutputBuffers ( ) { } @ Override public void addStateChangeListener ( final StateChangeListener < StageInfo > stateChangeListener ) { } private Multimap < PlanNodeId , URI > getNewExchangeLocations ( ) { } @ Override @ VisibleForTesting public synchronized List < URI > getTaskLocations ( ) { } @ VisibleForTesting public List < RemoteTask > getAllTasks ( ) { } @ VisibleForTesting public List < RemoteTask > getTasks ( Node node ) { } public Future < ? > start ( ) { } @ Override @ VisibleForTesting public Future < ? > scheduleStartTasks ( ) { } private void startTasks ( ) { } private void scheduleFixedNodeCount ( int nodeCount ) { } private void scheduleOnCurrentNode ( ) { } private void scheduleSourcePartitionedNodes ( ) throws InterruptedException { } private void assignSplits ( AtomicInteger nextTaskId , Multimap < Node , Split > splitAssignment ) { } private void waitForFreeNode ( AtomicInteger nextTaskId ) { } private void addStageNode ( TaskId task ) { } private void setNoMoreStageNodes ( ) { } private RemoteTask scheduleTask ( int id , Node node ) { } private RemoteTask scheduleTask ( int id , Node node , PlanNodeId sourceId , Iterable < ? extends Split > sourceSplits ) { } private void updateNewExchangesAndBuffers ( boolean waitUntilFinished ) { } private boolean addNewExchangesAndBuffers ( ) { } private synchronized void waitForNewExchangesOrBuffers ( ) { } private Set < PlanNodeId > updateCompleteSources ( ) { } @ VisibleForTesting public void doUpdateState ( ) { Preconditions . checkState ( ( ! ( Thread . holdsLock ( this ) ) ) , "Can<seq2seq4repair_space>not<seq2seq4repair_space>doUpdateState<seq2seq4repair_space>while<seq2seq4repair_space>holding<seq2seq4repair_space>a<seq2seq4repair_space>lock<seq2seq4repair_space>on<seq2seq4repair_space>this" ) ; try ( SetThreadName setThreadName = new SetThreadName ( "Stage-%s" , stageId ) ) { synchronized ( this ) { this . notifyAll ( ) ; StageState currentState = stageState . get ( ) ; if ( currentState . isDone ( ) ) { return ; } List < StageState > subStageStates = ImmutableList . copyOf ( Iterables . transform ( Iterables . transform ( subStages . values ( ) , StageExecutionNode :: getStageInfo ) , StageInfo :: getState ) ) ; if ( subStageStates . stream ( ) . anyMatch ( StageState :: isFailure ) ) { stageState . set ( ABORTED ) ; } else { List < TaskState > taskStates = ImmutableList . copyOf ( Iterables . transform ( Iterables . transform ( tasks . values ( ) , RemoteTask :: getTaskInfo ) , TaskInfo :: getState ) ) ; if ( Iterables . any ( taskStates , Predicates . equalTo ( FAILED ) ) ) { stageState . set ( StageState . FAILED ) ; } else if ( Iterables . any ( taskStates , Predicates . equalTo ( TaskState . ABORTED ) ) ) { stageState . set ( StageState . FAILED ) ; <START_BUG> failureCauses . add ( new com . facebook . presto . spi . PrestoException ( StandardErrorCode . INTERNAL_ERROR , ( "A<seq2seq4repair_space>task<seq2seq4repair_space>is<seq2seq4repair_space>in<seq2seq4repair_space>the<seq2seq4repair_space>ABORTED<seq2seq4repair_space>state<seq2seq4repair_space>but<seq2seq4repair_space>stage<seq2seq4repair_space>is<seq2seq4repair_space>" + ( stageState ) ) ) ) ; <END_BUG> } else if ( ( currentState != ( StageState . PLANNED ) ) && ( currentState != ( StageState . SCHEDULING ) ) ) { if ( Iterables . all ( taskStates , TaskState :: isDone ) ) { stageState . set ( FINISHED ) ; } else if ( Iterables . any ( taskStates , Predicates . equalTo ( RUNNING ) ) ) { stageState . set ( StageState . RUNNING ) ; } } } } StageState stageState = this . stageState . get ( ) ; if ( stageState == ( StageState . ABORTED ) ) { abort ( ) ; } else if ( stageState . isDone ( ) ) { cancel ( ) ; } } } @ Override public void cancel ( ) { } @ Override public void abort ( ) { } private static Split createRemoteSplitFor ( TaskId taskId , URI taskLocation ) { } @ Override public String toString ( ) { } private static Optional < Integer > getHashChannel ( PlanFragment fragment ) { } private static List < Integer > getPartitioningChannels ( PlanFragment fragment ) { } }

Fix:
failureCauses . add ( new com . facebook . presto . spi . PrestoException ( StandardErrorCode . INTERNAL_ERROR , ( "A<seq2seq4repair_space>task<seq2seq4repair_space>is<seq2seq4repair_space>in<seq2seq4repair_space>the<seq2seq4repair_space>ABORTED<seq2seq4repair_space>state<seq2seq4repair_space>but<seq2seq4repair_space>stage<seq2seq4repair_space>is<seq2seq4repair_space>" + currentState ) ) ) ;