Buggy code:
public void testBigNumericRange ( ) throws IOException { } public void testBigNumericRange2 ( ) throws IOException { } public void testBytes ( ) throws IOException { } public void testBytesTwoDocumentsMerged ( ) throws IOException { } public void testSortedBytes ( ) throws IOException { } public void testSortedBytesTwoDocuments ( ) throws IOException { } public void testSortedBytesThreeDocuments ( ) throws IOException { } public void testSortedBytesTwoDocumentsMerged ( ) throws IOException { } public void testBytesWithNewline ( ) throws IOException { } public void testMissingSortedBytes ( ) throws IOException { } public void testEmptySortedBytes ( ) throws IOException { } public void testEmptyBytes ( ) throws IOException { } public void testVeryLargeButLegalBytes ( ) throws IOException { } public void testVeryLargeButLegalSortedBytes ( ) throws IOException { } public void testCodecUsesOwnBytes ( ) throws IOException { } public void testCodecUsesOwnSortedBytes ( ) throws IOException { } public void testCodecUsesOwnBytesEachTime ( ) throws IOException { } public void testCodecUsesOwnSortedBytesEachTime ( ) throws IOException { } public void testDocValuesSimple ( ) throws IOException { } public void testRandomSortedBytes ( ) throws IOException { Directory dir = newDirectory ( ) ; IndexWriterConfig cfg = newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) ; IndexWriter w = new IndexWriter ( dir , cfg ) ; int numDocs = atLeast ( 100 ) ; BytesRefHash hash = new BytesRefHash ( ) ; Map < String , String > docToString = new HashMap < String , String > ( ) ; int maxLength = _TestUtil . nextInt ( random ( ) , 1 , 50 ) ; for ( int i = 0 ; i < numDocs ; i ++ ) { Document doc = new Document ( ) ; doc . add ( newTextField ( "id" , ( "" + i ) , YES ) ) ; String string = _TestUtil . randomRealisticUnicodeString ( random ( ) , 1 , maxLength ) ; BytesRef br = new BytesRef ( string ) ; doc . add ( new org . apache . lucene . document . SortedDocValuesField ( "field" , br ) ) ; hash . add ( br ) ; docToString . put ( ( "" + i ) , string ) ; w . addDocument ( doc ) ; } if ( rarely ( ) ) { w . commit ( ) ; } int numDocsNoValue = atLeast ( 10 ) ; for ( int i = 0 ; i < numDocsNoValue ; i ++ ) { Document doc = new Document ( ) ; doc . add ( newTextField ( "id" , "noValue" , YES ) ) ; w . addDocument ( doc ) ; } BytesRef bytesRef = new BytesRef ( ) ; hash . add ( bytesRef ) ; if ( rarely ( ) ) { w . commit ( ) ; } for ( int i = 0 ; i < numDocs ; i ++ ) { Document doc = new Document ( ) ; String id = ( "" + i ) + numDocs ; doc . add ( newTextField ( "id" , id , YES ) ) ; String string = _TestUtil . randomRealisticUnicodeString ( random ( ) , 1 , maxLength ) ; BytesRef br = new BytesRef ( string ) ; hash . add ( br ) ; docToString . put ( id , string ) ; doc . add ( new org . apache . lucene . document . SortedDocValuesField ( "field" , br ) ) ; w . addDocument ( doc ) ; } w . commit ( ) ; IndexReader reader = w . getReader ( ) ; SortedDocValues docValues = MultiDocValues . getSortedValues ( reader , "field" ) ; int [ ] sort = hash . sort ( BytesRef . getUTF8SortedAsUnicodeComparator ( ) ) ; BytesRef expected = new BytesRef ( ) ; BytesRef actual = new BytesRef ( ) ; assertEquals ( hash . size ( ) , docValues . getValueCount ( ) ) ; for ( int i = 0 ; i < ( hash . size ( ) ) ; i ++ ) { hash . get ( sort [ i ] , expected ) ; docValues . lookupOrd ( i , actual ) ; assertEquals ( expected . utf8ToString ( ) , actual . utf8ToString ( ) ) ; <START_BUG> int ord = docValues . lookupTerm ( expected , actual ) ; <END_BUG> assertEquals ( i , ord ) ; } AtomicReader slowR = SlowCompositeReaderWrapper . wrap ( reader ) ; Set < Map . Entry < String , String > > entrySet = docToString . entrySet ( ) ; for ( Map . Entry < String , String > entry : entrySet ) { DocsEnum termDocsEnum = slowR . termDocsEnum ( new Term ( "id" , entry . getKey ( ) ) ) ; int docId = termDocsEnum . nextDoc ( ) ; expected = new BytesRef ( entry . getValue ( ) ) ; docValues . get ( docId , actual ) ; assertEquals ( expected , actual ) ; } reader . close ( ) ; w . close ( ) ; dir . close ( ) ; } private void doTestNumericsVsStoredFields ( long minValue , long maxValue ) throws Exception { } public void testBooleanNumericsVsStoredFields ( ) throws Exception { } public void testByteNumericsVsStoredFields ( ) throws Exception { } public void testShortNumericsVsStoredFields ( ) throws Exception { } public void testIntNumericsVsStoredFields ( ) throws Exception { } public void testLongNumericsVsStoredFields ( ) throws Exception { } private void doTestBinaryVsStoredFields ( int minLength , int maxLength ) throws Exception { } public void testBinaryFixedLengthVsStoredFields ( ) throws Exception { } public void testBinaryVariableLengthVsStoredFields ( ) throws Exception { } private void doTestSortedVsStoredFields ( int minLength , int maxLength ) throws Exception { } public void testSortedFixedLengthVsStoredFields ( ) throws Exception { } public void testSortedVariableLengthVsStoredFields ( ) throws Exception { } }

Fix:
int ord = docValues . lookupTerm ( expected ) ;