Buggy code:
@ SuppressTempFileChecks ( bugUrl = "https:////issues.apache.org//jira//browse//SOLR-1877<seq2seq4repair_space>Spellcheck<seq2seq4repair_space>IndexReader<seq2seq4repair_space>leak<seq2seq4repair_space>bug?" ) public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 { protected static SpellingQueryConverter queryConverter ; protected static String [ ] DOCS = new String [ ] { "This<seq2seq4repair_space>is<seq2seq4repair_space>a<seq2seq4repair_space>title" , "The<seq2seq4repair_space>quick<seq2seq4repair_space>reb<seq2seq4repair_space>fox<seq2seq4repair_space>jumped<seq2seq4repair_space>over<seq2seq4repair_space>the<seq2seq4repair_space>lazy<seq2seq4repair_space>brown<seq2seq4repair_space>dogs." , "This<seq2seq4repair_space>is<seq2seq4repair_space>a<seq2seq4repair_space>document" , "another<seq2seq4repair_space>document" , "red<seq2seq4repair_space>fox" , "green<seq2seq4repair_space>bun" , "green<seq2seq4repair_space>bud" } ; @ BeforeClass public static void beforeClass ( ) throws Exception { } @ AfterClass public static void afterClass ( ) { } @ Test public void testComparator ( ) throws Exception { } @ Test public void testSpelling ( ) throws Exception { } @ Test public void testExtendedResults ( ) throws Exception { } private class TestSpellChecker extends IndexBasedSpellChecker { @ Override public SpellChecker getSpellChecker ( ) { } } @ Test public void testAlternateDistance ( ) throws Exception { } @ Test public void testAlternateLocation ( ) throws Exception { String [ ] ALT_DOCS = new String [ ] { "jumpin<seq2seq4repair_space>jack<seq2seq4repair_space>flash" , "Sargent<seq2seq4repair_space>Peppers<seq2seq4repair_space>Lonely<seq2seq4repair_space>Hearts<seq2seq4repair_space>Club<seq2seq4repair_space>Band" , "Born<seq2seq4repair_space>to<seq2seq4repair_space>Run" , "Thunder<seq2seq4repair_space>Road" , "Londons<seq2seq4repair_space>Burning" , "A<seq2seq4repair_space>Horse<seq2seq4repair_space>with<seq2seq4repair_space>No<seq2seq4repair_space>Name" , "Sweet<seq2seq4repair_space>Caroline" } ; IndexBasedSpellChecker checker = new IndexBasedSpellChecker ( ) ; NamedList spellchecker = new NamedList ( ) ; spellchecker . add ( "classname" , IndexBasedSpellChecker . class . getName ( ) ) ; File tmpDir = createTempDir ( ) ; File indexDir = new File ( tmpDir , "spellingIdx" ) ; File altIndexDir = new File ( tmpDir , ( "alternateIdx" + ( new Date ( ) . getTime ( ) ) ) ) ; Directory dir = newFSDirectory ( altIndexDir ) ; IndexWriter iw = new IndexWriter ( dir , new org . apache . lucene . index . IndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . core . WhitespaceAnalyzer ( TEST_VERSION_CURRENT ) ) ) ; for ( int i = 0 ; i < ( ALT_DOCS . length ) ; i ++ ) { Document doc = new Document ( ) ; doc . add ( new org . apache . lucene . document . TextField ( "title" , ALT_DOCS [ i ] , Store . YES ) ) ; iw . addDocument ( doc ) ; } iw . forceMerge ( 1 ) ; <START_BUG> iw . close ( ) ; <END_BUG> dir . close ( ) ; indexDir . mkdirs ( ) ; spellchecker . add ( INDEX_DIR , indexDir . getAbsolutePath ( ) ) ; spellchecker . add ( LOCATION , altIndexDir . getAbsolutePath ( ) ) ; spellchecker . add ( FIELD , "title" ) ; spellchecker . add ( SPELLCHECKER_ARG_NAME , spellchecker ) ; SolrCore core = h . getCore ( ) ; String dictName = checker . init ( spellchecker , core ) ; assertTrue ( ( ( dictName + "<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>equal<seq2seq4repair_space>to<seq2seq4repair_space>" ) + ( SolrSpellChecker . DEFAULT_DICTIONARY_NAME ) ) , ( ( dictName . equals ( DEFAULT_DICTIONARY_NAME ) ) == true ) ) ; RefCounted < SolrIndexSearcher > holder = core . getSearcher ( ) ; SolrIndexSearcher searcher = holder . get ( ) ; try { checker . build ( core , searcher ) ; IndexReader reader = searcher . getIndexReader ( ) ; Collection < Token > tokens = IndexBasedSpellCheckerTest . queryConverter . convert ( "flesh" ) ; SpellingOptions spellOpts = new SpellingOptions ( tokens , reader , 1 , SuggestMode . SUGGEST_WHEN_NOT_IN_INDEX , true , 0.5F , null ) ; SpellingResult result = checker . getSuggestions ( spellOpts ) ; assertTrue ( "result<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( result != null ) ) ; Map < String , Integer > suggestions = result . get ( spellOpts . tokens . iterator ( ) . next ( ) ) ; assertTrue ( "flesh<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( suggestions != null ) ) ; assertTrue ( ( ( ( "flesh<seq2seq4repair_space>Size:<seq2seq4repair_space>" + ( suggestions . size ( ) ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>not:<seq2seq4repair_space>" ) + 1 ) , ( ( suggestions . size ( ) ) == 1 ) ) ; Map . Entry < String , Integer > entry = suggestions . entrySet ( ) . iterator ( ) . next ( ) ; assertTrue ( ( ( ( entry . getKey ( ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>equal<seq2seq4repair_space>to<seq2seq4repair_space>" ) + "flash" ) , ( ( entry . getKey ( ) . equals ( "flash" ) ) == true ) ) ; assertTrue ( ( ( ( entry . getValue ( ) ) + "<seq2seq4repair_space>does<seq2seq4repair_space>not<seq2seq4repair_space>equal:<seq2seq4repair_space>" ) + 1 ) , ( ( entry . getValue ( ) ) == 1 ) ) ; spellOpts . tokens = IndexBasedSpellCheckerTest . queryConverter . convert ( "super" ) ; result = checker . getSuggestions ( spellOpts ) ; assertTrue ( "result<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( result != null ) ) ; suggestions = result . get ( spellOpts . tokens . iterator ( ) . next ( ) ) ; assertTrue ( "suggestions<seq2seq4repair_space>size<seq2seq4repair_space>should<seq2seq4repair_space>be<seq2seq4repair_space>0" , ( ( suggestions . size ( ) ) == 0 ) ) ; spellOpts . tokens = IndexBasedSpellCheckerTest . queryConverter . convert ( "Caroline" ) ; result = checker . getSuggestions ( spellOpts ) ; assertTrue ( "result<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>shouldn't<seq2seq4repair_space>be" , ( result != null ) ) ; suggestions = result . get ( spellOpts . tokens . iterator ( ) . next ( ) ) ; assertTrue ( "suggestions<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>null<seq2seq4repair_space>and<seq2seq4repair_space>it<seq2seq4repair_space>should<seq2seq4repair_space>be" , ( suggestions == null ) ) ; } finally { holder . decref ( ) ; } } }

Fix:
iw . shutdown ( ) ;