Buggy code:
public class SpellCheckComponent extends SearchComponent implements SpellingParams , SolrCoreAware { private static final Logger LOG = LoggerFactory . getLogger ( SpellCheckComponent . class ) ; public static final boolean DEFAULT_ONLY_MORE_POPULAR = false ; public static final String COMPONENT_NAME = "spellcheck" ; @ SuppressWarnings ( "unchecked" ) protected NamedList initParams ; protected Map < String , SolrSpellChecker > spellCheckers = new ConcurrentHashMap < String , SolrSpellChecker > ( ) ; protected QueryConverter queryConverter ; @ Override @ SuppressWarnings ( "unchecked" ) public void init ( NamedList args ) { } @ Override @ SuppressWarnings ( "unchecked" ) public void prepare ( ResponseBuilder rb ) throws IOException { } @ Override @ SuppressWarnings ( "unchecked" ) public void process ( ResponseBuilder rb ) throws IOException { } @ SuppressWarnings ( "unchecked" ) protected void addCollationsToResponse ( SolrParams params , SpellingResult spellingResult , ResponseBuilder rb , String q , NamedList response , boolean suggestionsMayOverlap ) { } protected SolrParams getCustomParams ( String dictionary , SolrParams params ) { } @ Override public void modifyRequest ( ResponseBuilder rb , SearchComponent who , ShardRequest sreq ) { } @ Override @ SuppressWarnings ( { "unchecked" , "deprecation" } ) public void finishStage ( ResponseBuilder rb ) { } @ SuppressWarnings ( "unchecked" ) private void collectShardSuggestions ( NamedList nl , SpellCheckMergeData mergeData ) { } @ SuppressWarnings ( "unchecked" ) private void collectShardCollations ( SpellCheckMergeData mergeData , NamedList spellCheckResponse , int maxCollationTries ) { } private Collection < Token > getTokens ( String q , Analyzer analyzer ) throws IOException { } protected SolrSpellChecker getSpellChecker ( SolrParams params ) { } private String getDictionaryNameAsSingleString ( String [ ] dictName ) { } private String [ ] getDictionaryNames ( SolrParams params ) { } public SolrSpellChecker getSpellChecker ( String name ) { } protected NamedList toNamedList ( boolean shardRequest , SpellingResult spellingResult , String origQuery , boolean extendedResults , boolean collate , boolean correctlySpelled ) { } public void inform ( SolrCore core ) { } private static class SpellCheckerListener implements SolrEventListener { private final SolrCore core ; private final SolrSpellChecker checker ; private final boolean buildOnCommit ; private final boolean buildOnOptimize ; public SpellCheckerListener ( SolrCore core , SolrSpellChecker checker , boolean buildOnCommit , boolean buildOnOptimize ) { } public void init ( NamedList args ) { } public void newSearcher ( SolrIndexSearcher newSearcher , SolrIndexSearcher currentSearcher ) { if ( currentSearcher == null ) { try { SpellCheckComponent . LOG . info ( ( "Loading<seq2seq4repair_space>spell<seq2seq4repair_space>index<seq2seq4repair_space>for<seq2seq4repair_space>spellchecker:<seq2seq4repair_space>" + ( checker . getDictionaryName ( ) ) ) ) ; checker . reload ( core , newSearcher ) ; } catch ( IOException e ) { log . error ( ( "Exception<seq2seq4repair_space>in<seq2seq4repair_space>reloading<seq2seq4repair_space>spell<seq2seq4repair_space>check<seq2seq4repair_space>index<seq2seq4repair_space>for<seq2seq4repair_space>spellchecker:<seq2seq4repair_space>" + ( checker . getDictionaryName ( ) ) ) , e ) ; } } else { if ( buildOnCommit ) { buildSpellIndex ( newSearcher ) ; } else if ( buildOnOptimize ) { <START_BUG> if ( ( newSearcher . getIndexReader ( ) . getSequentialSubReaders ( ) . size ( ) ) == 1 ) { <END_BUG> buildSpellIndex ( newSearcher ) ; } else { SpellCheckComponent . LOG . info ( ( "Index<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>optimized<seq2seq4repair_space>therefore<seq2seq4repair_space>skipping<seq2seq4repair_space>building<seq2seq4repair_space>spell<seq2seq4repair_space>check<seq2seq4repair_space>index<seq2seq4repair_space>for:<seq2seq4repair_space>" + ( checker . getDictionaryName ( ) ) ) ) ; } } } } private void buildSpellIndex ( SolrIndexSearcher newSearcher ) { } public void postCommit ( ) { } @ Override public void postSoftCommit ( ) { } } public Map < String , SolrSpellChecker > getSpellCheckers ( ) { } @ Override public String getDescription ( ) { } @ Override public String getSource ( ) { } }

Fix:
if ( ( newSearcher . getIndexReader ( ) . leaves ( ) . size ( ) ) == 1 ) {