Index: src/test/org/apache/lucene/index/FlexTestUtil.java =================================================================== --- src/test/org/apache/lucene/index/FlexTestUtil.java (revision 923269) +++ src/test/org/apache/lucene/index/FlexTestUtil.java (working copy) @@ -105,8 +105,18 @@ testStraightEnum(r); testRandomSkips(rand, r); testRandomSeeks(rand, r); + testBogusFieldTerms(rand, r); } + private static void testBogusFieldTerms(Random rand, IndexReader r) throws Exception { + final Fields fields = MultiFields.getFields(r); + for(int i=0;i<10;i++) { + final String f = "bogus" + rand.nextInt() + "reallybogus"; + Terms terms = fields.terms(f); + assertTrue(terms == null || terms.iterator().next() == null); + } + } + private static void testStraightEnum(IndexReader r) throws Exception { // straight enum of fields/terms/docs/positions Index: src/java/org/apache/lucene/index/LegacyFieldsEnum.java =================================================================== --- src/java/org/apache/lucene/index/LegacyFieldsEnum.java (revision 923269) +++ src/java/org/apache/lucene/index/LegacyFieldsEnum.java (working copy) @@ -127,7 +127,8 @@ if (terms == null) { // first next -- seek to start of field terms = r.terms(new Term(field, "")); - if (terms.term() == null) { + final Term t = terms.term(); + if (t == null || t.field != field) { return null; } else { tr.copy(terms.term().text());