Index: src/test/org/apache/lucene/search/TestSort.java =================================================================== --- src/test/org/apache/lucene/search/TestSort.java (revision 955617) +++ src/test/org/apache/lucene/search/TestSort.java (working copy) @@ -1039,4 +1039,24 @@ dir.close(); } + public void testLUCENE2142() throws IOException { + RAMDirectory indexStore = new RAMDirectory (); + IndexWriter writer = new IndexWriter(indexStore, new IndexWriterConfig( + TEST_VERSION_CURRENT, new MockAnalyzer())); + for (int i=0; i<5; i++) { + Document doc = new Document(); + doc.add (new Field ("string", "a"+i, Field.Store.NO, Field.Index.NOT_ANALYZED)); + doc.add (new Field ("string", "b"+i, Field.Store.NO, Field.Index.NOT_ANALYZED)); + writer.addDocument (doc); + } + writer.optimize(); // enforce one segment to have a higher unique term count in all cases + writer.close(); + sort.setSort( + new SortField("string", SortField.STRING), + new SortField("string2", SortField.STRING, true), + SortField.FIELD_DOC ); + // this should not throw AIOOBE or RuntimeEx + new IndexSearcher (indexStore, true).search(new MatchAllDocsQuery(), null, 500, sort); + } + }