Buggy code:
) protected TopGroups groupByFieldOrFunction ( IndexSearcher searcher , Filter filter , Query query , int groupOffset , int groupLimit ) throws IOException { int topN = groupOffset + groupLimit ; final AbstractFirstPassGroupingCollector firstPassCollector ; final AbstractAllGroupsCollector allGroupsCollector ; final AbstractAllGroupHeadsCollector allGroupHeadsCollector ; if ( ( groupFunction ) != null ) { firstPassCollector = new org . apache . lucene . search . grouping . function . FunctionFirstPassGroupingCollector ( groupFunction , valueSourceContext , groupSort , topN ) ; if ( allGroups ) { allGroupsCollector = new org . apache . lucene . search . grouping . function . FunctionAllGroupsCollector ( groupFunction , valueSourceContext ) ; } else { allGroupsCollector = null ; } if ( allGroupHeads ) { allGroupHeadsCollector = new org . apache . lucene . search . grouping . function . FunctionAllGroupHeadsCollector ( groupFunction , valueSourceContext , sortWithinGroup ) ; } else { allGroupHeadsCollector = null ; } } else if ( ( docValuesType ) != null ) { firstPassCollector = DVFirstPassGroupingCollector . create ( groupSort , topN , groupField , docValuesType , diskResidentDocValues ) ; if ( allGroups ) { allGroupsCollector = DVAllGroupsCollector . create ( groupField , docValuesType , diskResidentDocValues , initialSize ) ; } else { allGroupsCollector = null ; } if ( allGroupHeads ) { allGroupHeadsCollector = DVAllGroupHeadsCollector . create ( groupField , sortWithinGroup , docValuesType , diskResidentDocValues ) ; } else { allGroupHeadsCollector = null ; } } else { firstPassCollector = new org . apache . lucene . search . grouping . term . TermFirstPassGroupingCollector ( groupField , groupSort , topN ) ; if ( allGroups ) { allGroupsCollector = new TermAllGroupsCollector ( groupField , initialSize ) ; } else { allGroupsCollector = null ; } if ( allGroupHeads ) { allGroupHeadsCollector = TermAllGroupHeadsCollector . create ( groupField , sortWithinGroup , initialSize ) ; } else { allGroupHeadsCollector = null ; } } final Collector firstRound ; if ( ( allGroupHeads ) || ( allGroups ) ) { List < Collector > collectors = new ArrayList < Collector > ( ) ; collectors . add ( firstPassCollector ) ; if ( allGroupHeads ) { collectors . add ( allGroupsCollector ) ; } if ( allGroupHeads ) { collectors . add ( allGroupHeadsCollector ) ; } firstRound = MultiCollector . wrap ( collectors . toArray ( new Collector [ collectors . size ( ) ] ) ) ; } else { firstRound = firstPassCollector ; } CachingCollector cachedCollector = null ; if ( ( ( maxCacheRAMMB ) != null ) || ( ( maxDocsToCache ) != null ) ) { if ( ( maxCacheRAMMB ) != null ) { cachedCollector = CachingCollector . create ( firstRound , cacheScores , maxCacheRAMMB ) ; } else { cachedCollector = CachingCollector . create ( firstRound , cacheScores , maxDocsToCache ) ; } searcher . search ( query , filter , cachedCollector ) ; } else { searcher . search ( query , filter , firstRound ) ; } if ( allGroups ) { matchingGroups = allGroupsCollector . getGroups ( ) ; } else { matchingGroups = Collections . emptyList ( ) ; } if ( allGroupHeads ) { matchingGroupHeads = allGroupHeadsCollector . retrieveGroupHeads ( searcher . getIndexReader ( ) . maxDoc ( ) ) ; } else { matchingGroupHeads = new Bits . MatchNoBits ( searcher . getIndexReader ( ) . maxDoc ( ) ) ; } Collection < SearchGroup > topSearchGroups = firstPassCollector . getTopGroups ( groupOffset , fillSortFields ) ; if ( topSearchGroups == null ) { <START_BUG> return new TopGroups ( new SortField [ 0 ] , new SortField [ 0 ] , 0 , 0 , new GroupDocs [ 0 ] ) ; <END_BUG> } int topNInsideGroup = ( groupDocsOffset ) + ( groupDocsLimit ) ; AbstractSecondPassGroupingCollector secondPassCollector ; if ( ( groupFunction ) != null ) { secondPassCollector = new org . apache . lucene . search . grouping . function . FunctionSecondPassGroupingCollector ( ( ( Collection ) ( topSearchGroups ) ) , groupSort , sortWithinGroup , topNInsideGroup , includeScores , includeMaxScore , fillSortFields , groupFunction , valueSourceContext ) ; } else if ( ( docValuesType ) != null ) { secondPassCollector = DVSecondPassGroupingCollector . create ( groupField , diskResidentDocValues , docValuesType , ( ( Collection ) ( topSearchGroups ) ) , groupSort , sortWithinGroup , topNInsideGroup , includeScores , includeMaxScore , fillSortFields ) ; } else { secondPassCollector = new org . apache . lucene . search . grouping . term . TermSecondPassGroupingCollector ( groupField , ( ( Collection ) ( topSearchGroups ) ) , groupSort , sortWithinGroup , topNInsideGroup , includeScores , includeMaxScore , fillSortFields ) ; } if ( ( cachedCollector != null ) && ( cachedCollector . isCached ( ) ) ) { cachedCollector . replay ( secondPassCollector ) ; } else { searcher . search ( query , filter , secondPassCollector ) ; } if ( allGroups ) { return new TopGroups ( secondPassCollector . getTopGroups ( groupDocsOffset ) , matchingGroups . size ( ) ) ; } else { return secondPassCollector . getTopGroups ( groupDocsOffset ) ; } } protected TopGroups < ? > groupByDocBlock ( IndexSearcher searcher , Filter filter , Query query , int groupOffset , int groupLimit ) throws IOException { } public GroupingSearch setCachingInMB ( double maxCacheRAMMB , boolean cacheScores ) { } public GroupingSearch setCaching ( int maxDocsToCache , boolean cacheScores ) { } public GroupingSearch disableCaching ( ) { } public GroupingSearch setGroupSort ( Sort groupSort ) { } public GroupingSearch setSortWithinGroup ( Sort sortWithinGroup ) { } public GroupingSearch setGroupDocsOffset ( int groupDocsOffset ) { } public GroupingSearch setGroupDocsLimit ( int groupDocsLimit ) { } public GroupingSearch setFillSortFields ( boolean fillSortFields ) { } public GroupingSearch setIncludeScores ( boolean includeScores ) { } public GroupingSearch setIncludeMaxScore ( boolean includeMaxScore ) { } public GroupingSearch setAllGroups ( boolean allGroups ) { } @ SuppressWarnings ( { "unchecked" , "rawtypes" } ) public < T > Collection < T > getAllMatchingGroups ( ) { }

Fix:
return new TopGroups ( new SortField [ 0 ] , new SortField [ 0 ] , 0 , 0 , new GroupDocs [ 0 ] , Float . NaN ) ;