Buggy code:
public class SpellChecker implements Closeable { public static final float DEFAULT_ACCURACY = 0.5F ; public static final String F_WORD = "word" ; Directory spellIndex ; private float bStart = 2.0F ; private float bEnd = 1.0F ; private IndexSearcher searcher ; private final Object searcherLock = new Object ( ) ; private final Object modifyCurrentIndexLock = new Object ( ) ; private volatile boolean closed = false ; private float accuracy = SpellChecker . DEFAULT_ACCURACY ; private StringDistance sd ; private Comparator < SuggestWord > comparator ; public SpellChecker ( Directory spellIndex , StringDistance sd ) throws IOException { } public SpellChecker ( Directory spellIndex ) throws IOException { } public SpellChecker ( Directory spellIndex , StringDistance sd , Comparator < SuggestWord > comparator ) throws IOException { } public void setSpellIndex ( Directory spellIndexDir ) throws IOException { } public void setComparator ( Comparator < SuggestWord > comparator ) { } public Comparator < SuggestWord > getComparator ( ) { } public void setStringDistance ( StringDistance sd ) { } public StringDistance getStringDistance ( ) { } public void setAccuracy ( float acc ) { } public float getAccuracy ( ) { } public String [ ] suggestSimilar ( String word , int numSug ) throws IOException { } public String [ ] suggestSimilar ( String word , int numSug , float accuracy ) throws IOException { } public String [ ] suggestSimilar ( String word , int numSug , IndexReader ir , String field , SuggestMode suggestMode ) throws IOException { } public String [ ] suggestSimilar ( String word , int numSug , IndexReader ir , String field , SuggestMode suggestMode , float accuracy ) throws IOException { } private static void add ( BooleanQuery q , String name , String value , float boost ) { } private static void add ( BooleanQuery q , String name , String value ) { } private static String [ ] formGrams ( String text , int ng ) { } public void clearIndex ( ) throws IOException { } public boolean exist ( String word ) throws IOException { } public final void indexDictionary ( Dictionary dict , IndexWriterConfig config , boolean fullMerge ) throws IOException { synchronized ( modifyCurrentIndexLock ) { ensureOpen ( ) ; final Directory dir = this . spellIndex ; final IndexWriter writer = new IndexWriter ( dir , config ) ; IndexSearcher indexSearcher = obtainSearcher ( ) ; final List < TermsEnum > termsEnums = new ArrayList < TermsEnum > ( ) ; final IndexReader reader = searcher . getIndexReader ( ) ; if ( ( reader . maxDoc ( ) ) > 0 ) { <START_BUG> for ( final AtomicReaderContext ctx : reader . getTopReaderContext ( ) . leaves ( ) ) { <END_BUG> Terms terms = ctx . reader ( ) . terms ( SpellChecker . F_WORD ) ; if ( terms != null ) termsEnums . add ( terms . iterator ( null ) ) ; } } boolean isEmpty = termsEnums . isEmpty ( ) ; try { BytesRefIterator iter = dict . getWordsIterator ( ) ; BytesRef currentTerm ; terms : while ( ( currentTerm = iter . next ( ) ) != null ) { String word = currentTerm . utf8ToString ( ) ; int len = word . length ( ) ; if ( len < 3 ) { continue ; } if ( ! isEmpty ) { for ( TermsEnum te : termsEnums ) { if ( te . seekExact ( currentTerm , false ) ) { continue terms ; } } } Document doc = SpellChecker . createDocument ( word , SpellChecker . getMin ( len ) , SpellChecker . getMax ( len ) ) ; writer . addDocument ( doc ) ; } } finally { releaseSearcher ( indexSearcher ) ; } if ( fullMerge ) { writer . forceMerge ( 1 ) ; } writer . close ( ) ; swapSearcher ( dir ) ; } } private static int getMin ( int l ) { } private static int getMax ( int l ) { } private static Document createDocument ( String text , int ng1 , int ng2 ) { } private static void addGram ( String text , Document doc , int ng1 , int ng2 ) { } private IndexSearcher obtainSearcher ( ) { } private void releaseSearcher ( final IndexSearcher aSearcher ) throws IOException { } private void ensureOpen ( ) { } public void close ( ) throws IOException { } private void swapSearcher ( final Directory dir ) throws IOException { } IndexSearcher createSearcher ( final Directory dir ) throws IOException { } boolean isClosed ( ) { } }

Fix:
for ( final AtomicReaderContext ctx : reader . leaves ( ) ) {