Buggy code:
@ Component @ Scope ( "request" ) public class JoinQueryExecutor { private static final Logger log = LoggerFactory . getLogger ( AbstractDocumentQuery . class ) ; public enum QueryType { VARIABLE , DATASET , STUDY , NETWORK ; } @ Inject private AggregationsService aggregationsService ; @ Inject private VariableQuery variableQuery ; @ Inject private DatasetQuery datasetQuery ; @ Inject private StudyQuery studyQuery ; @ Inject private NetworkQuery networkQuery ; @ Inject private Dtos dtos ; @ Inject private OpalService opalService ; @ Timed public JoinQueryResultDto queryCoverage ( JoinQueryExecutor . QueryType type , JoinQueryDto joinQueryDto ) throws IOException { } @ Timed public JoinQueryResultDto listQuery ( JoinQueryExecutor . QueryType type , MicaSearch . QueryDto queryDto , String locale ) throws IOException { } private JoinQueryDto createJoinQueryByType ( JoinQueryExecutor . QueryType type , MicaSearch . QueryDto queryDto ) { } @ Timed public JoinQueryResultDto query ( JoinQueryExecutor . QueryType type , JoinQueryDto joinQueryDto ) throws IOException { } private JoinQueryResultDto query ( JoinQueryExecutor . QueryType type , JoinQueryDto joinQueryDto , CountStatsData . Builder countBuilder , AbstractDocumentQuery . Scope scope , AbstractDocumentQuery . Mode mode ) throws IOException { DatasetIdProvider datasetIdProvider = new DatasetIdProvider ( ) ; String locale = joinQueryDto . getLocale ( ) ; variableQuery . initialize ( ( joinQueryDto . hasVariableQueryDto ( ) ? joinQueryDto . getVariableQueryDto ( ) : null ) , locale , mode ) ; datasetQuery . initialize ( ( joinQueryDto . hasDatasetQueryDto ( ) ? joinQueryDto . getDatasetQueryDto ( ) : null ) , locale , mode ) ; studyQuery . initialize ( ( joinQueryDto . hasStudyQueryDto ( ) ? joinQueryDto . getStudyQueryDto ( ) : null ) , locale , mode ) ; networkQuery . initialize ( ( joinQueryDto . hasNetworkQueryDto ( ) ? joinQueryDto . getNetworkQueryDto ( ) : null ) , locale , mode ) ; boolean queriesHaveFilters = ( Stream . of ( variableQuery , datasetQuery , studyQuery , networkQuery ) . filter ( AbstractDocumentQuery :: hasQueryFilters ) . collect ( Collectors . toList ( ) ) . size ( ) ) > 0 ; if ( queriesHaveFilters ) { variableQuery . setDatasetIdProvider ( datasetIdProvider ) ; datasetQuery . setDatasetIdProvider ( datasetIdProvider ) ; List < String > joinedIds = executeJoin ( type ) ; CountStatsData countStats = ( countBuilder != null ) ? getCountStatsData ( type ) : null ; if ( ( joinedIds != null ) && ( ( joinedIds . size ( ) ) > 0 ) ) { getDocumentQuery ( type ) . query ( joinedIds , countStats , scope ) ; if ( type == ( JoinQueryExecutor . QueryType . VARIABLE ) ) { datasetQuery . query ( joinedIds , null , DIGEST ) ; } else if ( type == ( JoinQueryExecutor . QueryType . DATASET ) ) { variableQuery . query ( joinedIds , null , DIGEST ) ; } } else if ( ! ( studyQuery . hasQueryFilters ( ) ) ) { variableQuery . query ( joinedIds , null , DIGEST ) ; if ( ! ( datasetIdProvider . getDatasetIds ( ) . isEmpty ( ) ) ) { if ( type != ( JoinQueryExecutor . QueryType . DATASET ) ) { datasetQuery . query ( joinedIds , null , DIGEST ) ; } if ( ( type == ( JoinQueryExecutor . QueryType . VARIABLE ) ) || ( type == ( JoinQueryExecutor . QueryType . DATASET ) ) ) { getDocumentQuery ( type ) . query ( joinedIds , countStats , scope ) ; } } List < String > tmp = new ArrayList < > ( ) ; tmp . add ( "" ) ; studyQuery . query ( tmp , null , DIGEST ) ; } } else { execute ( type , scope , countBuilder ) ; } JoinQueryResultDto . Builder builder = JoinQueryResultDto . newBuilder ( ) ; AggregationsConfig aggregationsConfig = aggregationsService . getAggregationsConfig ( ) ; <START_BUG> builder . setVariableResultDto ( addAggregationTitles ( variableQuery . getResultQuery ( ) , aggregationsConfig . getVariableAggregations ( ) , ( mode == ( Mode . COVERAGE ) ? null : aggregationPostProcessor ( ) ) ) ) ; <END_BUG> if ( ( datasetQuery . getResultQuery ( ) ) != null ) { builder . setDatasetResultDto ( addAggregationTitles ( datasetQuery . getResultQuery ( ) , aggregationsConfig . getDatasetAggregations ( ) , null ) ) ; } builder . setStudyResultDto ( addAggregationTitles ( studyQuery . getResultQuery ( ) , aggregationsConfig . getStudyAggregations ( ) , null ) ) ; if ( ( networkQuery . getResultQuery ( ) ) != null ) { builder . setNetworkResultDto ( addAggregationTitles ( networkQuery . getResultQuery ( ) , aggregationsConfig . getNetworkAggregations ( ) , null ) ) ; } return builder . build ( ) ; } private QueryResultDto addAggregationTitles ( MicaSearch . QueryResultDto queryResultDto , List < AggregationInfo > aggregationsList , Function < List < MicaSearch . AggregationResultDto > , List < MicaSearch . AggregationResultDto > > postProcessor ) { } protected Function < List < MicaSearch . AggregationResultDto > , List < MicaSearch . AggregationResultDto > > aggregationPostProcessor ( ) { } private void execute ( JoinQueryExecutor . QueryType type , AbstractDocumentQuery . Scope scope , CountStatsData . Builder countBuilder ) throws IOException { } private List < String > executeJoin ( JoinQueryExecutor . QueryType type ) throws IOException { } private AbstractDocumentQuery getDocumentQuery ( JoinQueryExecutor . QueryType type ) { } private CountStatsData getCountStatsData ( JoinQueryExecutor . QueryType type ) { } private List < String > execute ( AbstractDocumentQuery docQuery , AbstractDocumentQuery ... subQueries ) throws IOException { } private List < String > joinStudyIds ( List < String > studyIds , List < String > joinedStudyIds ) { } private void queryAggregations ( List < String > studyIds , AbstractDocumentQuery ... queries ) throws IOException { } private List < String > queryStudyIds ( List < AbstractDocumentQuery > queries ) throws IOException { } }

Fix:
builder . setVariableResultDto ( addAggregationTitles ( variableQuery . getResultQuery ( ) , aggregationsConfig . getVariableAggregations ( ) , aggregationPostProcessor ( ) ) ) ;