Buggy code:
public class CountingFacetsCollectorTest extends LuceneTestCase { private static final Term A = new Term ( "f" , "a" ) ; private static final CategoryPath CP_A = new CategoryPath ( "A" ) ; private static final CategoryPath CP_B = new CategoryPath ( "B" ) ; private static final int NUM_CHILDREN_CP_A = 5 ; private static final int NUM_CHILDREN_CP_B = 3 ; private static final CategoryPath [ ] CATEGORIES_A ; private static final CategoryPath [ ] CATEGORIES_B ; protected static Directory indexDir ; protected static Directory taxoDir ; protected static ObjectToIntMap < CategoryPath > allExpectedCounts ; protected static ObjectToIntMap < CategoryPath > termExpectedCounts ; protected static int numChildrenIndexedA ; protected static int numChildrenIndexedB ; @ AfterClass public static void afterClassCountingFacetsCollectorTest ( ) throws Exception { } private static List < CategoryPath > randomCategories ( Random random ) { } private static void addField ( Document doc ) { } private static void addFacets ( Document doc , FacetFields facetFields , boolean updateTermExpectedCounts ) throws IOException { } private static void indexDocsNoFacets ( IndexWriter indexWriter ) throws IOException { } private static void indexDocsWithFacetsNoTerms ( IndexWriter indexWriter , TaxonomyWriter taxoWriter , ObjectToIntMap < CategoryPath > expectedCounts ) throws IOException { } private static void indexDocsWithFacetsAndTerms ( IndexWriter indexWriter , TaxonomyWriter taxoWriter , ObjectToIntMap < CategoryPath > expectedCounts ) throws IOException { } private static void indexDocsWithFacetsAndSomeTerms ( IndexWriter indexWriter , TaxonomyWriter taxoWriter , ObjectToIntMap < CategoryPath > expectedCounts ) throws IOException { } private static ObjectToIntMap < CategoryPath > newCounts ( ) { } @ BeforeClass public static void beforeClassCountingFacetsCollectorTest ( ) throws Exception { } @ Test public void testInvalidValidParams ( ) throws Exception { } @ Test public void testDifferentNumResults ( ) throws Exception { } @ Test public void testResidue ( ) throws Exception { } @ Test public void testAllCounts ( ) throws Exception { } @ Test public void testBigNumResults ( ) throws Exception { } @ Test public void testDirectSource ( ) throws Exception { DirectoryReader indexReader = DirectoryReader . open ( CountingFacetsCollectorTest . indexDir ) ; TaxonomyReader taxoReader = new org . apache . lucene . facet . taxonomy . directory . DirectoryTaxonomyReader ( CountingFacetsCollectorTest . taxoDir ) ; IndexSearcher searcher = new IndexSearcher ( indexReader ) ; FacetSearchParams fsp = new FacetSearchParams ( new org . apache . lucene . facet . search . params . CountFacetRequest ( CountingFacetsCollectorTest . CP_A , CountingFacetsCollectorTest . NUM_CHILDREN_CP_A ) , new org . apache . lucene . facet . search . params . CountFacetRequest ( CountingFacetsCollectorTest . CP_B , CountingFacetsCollectorTest . NUM_CHILDREN_CP_B ) ) ; <START_BUG> FacetsCollector fc = new CountingFacetsCollector ( fsp , taxoReader , new FacetArrays ( taxoReader . getSize ( ) ) , true ) ; <END_BUG> searcher . search ( new MatchAllDocsQuery ( ) , fc ) ; List < FacetResult > facetResults = fc . getFacetResults ( ) ; assertEquals ( "invalid<seq2seq4repair_space>number<seq2seq4repair_space>of<seq2seq4repair_space>facet<seq2seq4repair_space>results" , 2 , facetResults . size ( ) ) ; for ( FacetResult res : facetResults ) { FacetResultNode root = res . getFacetResultNode ( ) ; assertEquals ( ( "wrong<seq2seq4repair_space>count<seq2seq4repair_space>for<seq2seq4repair_space>" + ( root . label ) ) , CountingFacetsCollectorTest . allExpectedCounts . get ( root . label ) , ( ( int ) ( root . value ) ) ) ; assertEquals ( "invalid<seq2seq4repair_space>residue" , 0 , ( ( int ) ( root . residue ) ) ) ; for ( FacetResultNode child : root . subResults ) { assertEquals ( ( "wrong<seq2seq4repair_space>count<seq2seq4repair_space>for<seq2seq4repair_space>" + ( child . label ) ) , CountingFacetsCollectorTest . allExpectedCounts . get ( child . label ) , ( ( int ) ( child . value ) ) ) ; } } IOUtils . close ( indexReader , taxoReader ) ; } @ Test public void testNoParents ( ) throws Exception { } }

Fix:
FacetsCollector fc = new CountingFacetsCollector ( fsp , taxoReader , new FacetArrays ( taxoReader . getSize ( ) ) ) ;