Buggy code:
public class TestDocValuesIndexing extends LuceneTestCase { public void testDocValuesSimple ( ) throws IOException { } public void testIndexBytesNoDeletes ( ) throws IOException { } public void testIndexBytesDeletes ( ) throws IOException { } public void testIndexNumericsNoDeletes ( ) throws IOException { } public void testIndexNumericsDeletes ( ) throws IOException { } public void testAddIndexes ( ) throws IOException { } public void testAddIndexesRandom ( ) throws IOException { } private IndexWriterConfig writerConfig ( boolean useCompoundFile ) { } @ SuppressWarnings ( "fallthrough" ) public void runTestNumerics ( IndexWriterConfig cfg , boolean withDeletions ) throws IOException { } public void runTestIndexBytes ( IndexWriterConfig cfg , boolean withDeletions ) throws IOException { } public void testGetArrayNumerics ( ) throws IOException { } public void testGetArrayBytes ( ) throws IOException { } public void testMultiValuedDocValuesField ( ) throws Exception { } public void testDifferentTypedDocValuesField ( ) throws Exception { } public void testDifferentTypedDocValuesField2 ( ) throws Exception { } public void testSortedBytes ( ) throws IOException { DocValuesType type = DocValuesType . SORTED ; final Directory d = newDirectory ( ) ; IndexWriterConfig cfg = newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . MockAnalyzer ( random ( ) ) ) ; IndexWriter w = new IndexWriter ( d , cfg ) ; int numDocs = atLeast ( 100 ) ; BytesRefHash hash = new BytesRefHash ( ) ; Map < String , String > docToString = new HashMap < String , String > ( ) ; int len = 1 + ( random ( ) . nextInt ( 50 ) ) ; for ( int i = 0 ; i < numDocs ; i ++ ) { Document doc = new Document ( ) ; doc . add ( newTextField ( "id" , ( "" + i ) , YES ) ) ; String string = _TestUtil . randomRealisticUnicodeString ( random ( ) , 1 , len ) ; BytesRef br = new BytesRef ( string ) ; doc . add ( new org . apache . lucene . document . SortedBytesDocValuesField ( "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 , len ) ; BytesRef br = new BytesRef ( string ) ; hash . add ( br ) ; docToString . put ( id , string ) ; doc . add ( new org . apache . lucene . document . SortedBytesDocValuesField ( "field" , br ) ) ; w . addDocument ( doc ) ; } w . commit ( ) ; IndexReader reader = w . getReader ( ) ; <START_BUG> SortedDocValues docValues = MultiSimpleDocValues . simpleSortedValues ( reader , "field" ) ; <END_BUG> 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 ( ) ) ; int ord = docValues . lookupTerm ( expected , actual ) ; assertEquals ( i , ord ) ; } AtomicReader slowR = SlowCompositeReaderWrapper . wrap ( reader ) ; Set < Map . Entry < String , String > > entrySet = docToString . entrySet ( ) ; for ( Map . Entry < String , String > entry : entrySet ) { int docId = docId ( slowR , new Term ( "id" , entry . getKey ( ) ) ) ; expected = new BytesRef ( entry . getValue ( ) ) ; docValues . get ( docId , actual ) ; assertEquals ( expected , actual ) ; } reader . close ( ) ; w . close ( ) ; d . close ( ) ; } public int docId ( AtomicReader reader , Term term ) throws IOException { } public void testWithThreads ( ) throws Exception { } public void testLengthPrefixAcrossTwoPages ( ) throws Exception { } public void testFixedLengthNotReallyFixed ( ) throws IOException { } public void testDocValuesUnstored ( ) throws IOException { } public void testMixedTypesSameDocument ( ) throws Exception { } public void testMixedTypesDifferentDocuments ( ) throws Exception { } public void testMixedTypesDifferentSegments ( ) throws Exception { } public void testMixedTypesAfterDeleteAll ( ) throws Exception { } public void testMixedTypesAfterReopenCreate ( ) throws Exception { } public void testMixedTypesDifferentThreads ( ) throws Exception { } public void testMixedTypesViaAddIndexes ( ) throws Exception { } public NumericDocValues numeric ( AtomicReader reader , String field ) throws IOException { } public NumericDocValues numeric ( DirectoryReader reader , String field ) throws IOException { }

Fix:
SortedDocValues docValues = MultiDocValues . getSortedValues ( reader , "field" ) ;