Buggy code:
iter < numberOfRuns ; iter ++ ) { if ( VERBOSE ) { System . out . println ( String . format ( "TEST:<seq2seq4repair_space>iter=%d<seq2seq4repair_space>total=%d" , iter , numberOfRuns ) ) ; } final int numDocs = ( _TestUtil . nextInt ( random , 100 , 1000 ) ) * ( RANDOM_MULTIPLIER ) ; final int numGroups = _TestUtil . nextInt ( random , 1 , numDocs ) ; if ( VERBOSE ) { System . out . println ( ( ( ( "TEST:<seq2seq4repair_space>numDocs=" + numDocs ) + "<seq2seq4repair_space>numGroups=" ) + numGroups ) ) ; } final List < BytesRef > groups = new ArrayList < BytesRef > ( ) ; for ( int i = 0 ; i < numGroups ; i ++ ) { String randomValue ; do { randomValue = _TestUtil . randomRealisticUnicodeString ( random ) ; } while ( "" . equals ( randomValue ) ) ; groups . add ( new BytesRef ( randomValue ) ) ; } final String [ ] contentStrings = new String [ _TestUtil . nextInt ( random , 2 , 20 ) ] ; if ( VERBOSE ) { System . out . println ( "TEST:<seq2seq4repair_space>create<seq2seq4repair_space>fake<seq2seq4repair_space>content" ) ; } for ( int contentIDX = 0 ; contentIDX < ( contentStrings . length ) ; contentIDX ++ ) { final StringBuilder sb = new StringBuilder ( ) ; sb . append ( "real" ) . append ( random . nextInt ( 3 ) ) . append ( '<seq2seq4repair_space>' ) ; final int fakeCount = random . nextInt ( 10 ) ; for ( int fakeIDX = 0 ; fakeIDX < fakeCount ; fakeIDX ++ ) { sb . append ( "fake<seq2seq4repair_space>" ) ; } contentStrings [ contentIDX ] = sb . toString ( ) ; if ( VERBOSE ) { System . out . println ( ( "<seq2seq4repair_space>content=" + ( sb . toString ( ) ) ) ) ; } } Directory dir = newDirectory ( ) ; RandomIndexWriter w = new RandomIndexWriter ( random , dir , newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ) ) ) ; boolean preFlex = "Lucene3x" . equals ( w . w . getConfig ( ) . getCodec ( ) . getName ( ) ) ; boolean canUseIDV = ! preFlex ; Type valueType = AllGroupHeadsCollectorTest . vts [ random . nextInt ( AllGroupHeadsCollectorTest . vts . length ) ] ; Document doc = new Document ( ) ; Document docNoGroup = new Document ( ) ; Field group = newField ( "group" , "" , TYPE_UNSTORED ) ; doc . add ( group ) ; DocValuesField valuesField = null ; if ( canUseIDV ) { valuesField = new DocValuesField ( "group" , valueType ) ; doc . add ( valuesField ) ; } Field sort1 = newField ( "sort1" , "" , TYPE_UNSTORED ) ; doc . add ( sort1 ) ; docNoGroup . add ( sort1 ) ; Field sort2 = newField ( "sort2" , "" , TYPE_UNSTORED ) ; doc . add ( sort2 ) ; docNoGroup . add ( sort2 ) ; Field sort3 = newField ( "sort3" , "" , TYPE_UNSTORED ) ; doc . add ( sort3 ) ; docNoGroup . add ( sort3 ) ; Field content = newField ( "content" , "" , TextField . TYPE_UNSTORED ) ; doc . add ( content ) ; docNoGroup . add ( content ) ; <START_BUG> NumericField id = new NumericField ( "id" ) ; <END_BUG> doc . add ( id ) ; docNoGroup . add ( id ) ; final AllGroupHeadsCollectorTest . GroupDoc [ ] groupDocs = new AllGroupHeadsCollectorTest . GroupDoc [ numDocs ] ; for ( int i = 0 ; i < numDocs ; i ++ ) { final BytesRef groupValue ; if ( ( random . nextInt ( 24 ) ) == 17 ) { groupValue = null ; } else { groupValue = groups . get ( random . nextInt ( groups . size ( ) ) ) ; } final AllGroupHeadsCollectorTest . GroupDoc groupDoc = new AllGroupHeadsCollectorTest . GroupDoc ( i , groupValue , groups . get ( random . nextInt ( groups . size ( ) ) ) , groups . get ( random . nextInt ( groups . size ( ) ) ) , new BytesRef ( String . format ( "%05d" , i ) ) , contentStrings [ random . nextInt ( contentStrings . length ) ] ) ; if ( VERBOSE ) { System . out . println ( ( ( ( ( ( ( ( ( ( ( ( "<seq2seq4repair_space>doc<seq2seq4repair_space>content=" + ( groupDoc . content ) ) + "<seq2seq4repair_space>id=" ) + i ) + "<seq2seq4repair_space>group=" ) + ( ( groupDoc . group ) == null ? "null" : groupDoc . group . utf8ToString ( ) ) ) + "<seq2seq4repair_space>sort1=" ) + ( groupDoc . sort1 . utf8ToString ( ) ) ) + "<seq2seq4repair_space>sort2=" ) + ( groupDoc . sort2 . utf8ToString ( ) ) ) + "<seq2seq4repair_space>sort3=" ) + ( groupDoc . sort3 . utf8ToString ( ) ) ) ) ; } groupDocs [ i ] = groupDoc ; if ( ( groupDoc . group ) != null ) { group . setValue ( groupDoc . group . utf8ToString ( ) ) ; if ( canUseIDV ) { valuesField . setBytes ( new BytesRef ( groupDoc . group . utf8ToString ( ) ) ) ; } } sort1 . setValue ( groupDoc . sort1 . utf8ToString ( ) ) ; sort2 . setValue ( groupDoc . sort2 . utf8ToString ( ) ) ; sort3 . setValue ( groupDoc . sort3 . utf8ToString ( ) ) ; content . setValue ( groupDoc . content ) ; id . setIntValue ( groupDoc . id ) ; if ( ( groupDoc . group ) == null ) { w . addDocument ( docNoGroup ) ; } else { w . addDocument ( doc ) ; } }

Fix:
NumericField id = new NumericField ( "id" , DataType . INT ) ;