Buggy code:
public class TestIndexReader extends LuceneTestCase { public void testCommitUserData ( ) throws Exception { } public void testIsCurrent ( ) throws Exception { } public void testGetFieldNames ( ) throws Exception { } public void testTermVectors ( ) throws Exception { } private void assertTermDocsCount ( String msg , IndexReader reader , Term term , int expected ) throws IOException { } public void testBasicDelete ( ) throws IOException { } public void testBinaryFields ( ) throws IOException { } public void testChangesAfterClose ( ) throws IOException { } public void testLockObtainFailed ( ) throws IOException { } public void testWritingNorms ( ) throws IOException { } public void testWritingNormsNoReader ( ) throws IOException { } public void testDeleteReaderWriterConflictUnoptimized ( ) throws IOException { } public void testDeleteReaderWriterConflictOptimized ( ) throws IOException { } private void deleteReaderWriterConflict ( boolean optimize ) throws IOException { } public void testFilesOpenClose ( ) throws IOException { } public void testLastModified ( ) throws Exception { } public void testVersion ( ) throws IOException { } public void testLock ( ) throws IOException { } public void testUndeleteAll ( ) throws IOException { } public void testUndeleteAllAfterClose ( ) throws IOException { } public void testUndeleteAllAfterCloseThenReopen ( ) throws IOException { } public void testDeleteReaderReaderConflictUnoptimized ( ) throws IOException { } public void testDeleteReaderReaderConflictOptimized ( ) throws IOException { } public void testDiskFull ( ) throws IOException { Term searchTerm = new Term ( "content" , "aaa" ) ; int START_COUNT = 157 ; int END_COUNT = 144 ; MockDirectoryWrapper startDir = newDirectory ( ) ; IndexWriter writer = new IndexWriter ( startDir , newIndexWriterConfig ( TEST_VERSION_CURRENT , new org . apache . lucene . analysis . WhitespaceAnalyzer ( TEST_VERSION_CURRENT ) ) ) ; for ( int i = 0 ; i < 157 ; i ++ ) { Document d = new Document ( ) ; d . add ( newField ( "id" , Integer . toString ( i ) , YES , NOT_ANALYZED ) ) ; d . add ( newField ( "content" , ( "aaa<seq2seq4repair_space>" + i ) , NO , ANALYZED ) ) ; writer . addDocument ( d ) ; } writer . close ( ) ; long diskUsage = startDir . getRecomputedActualSizeInBytes ( ) ; long diskFree = diskUsage + 100 ; IOException err = null ; boolean done = false ; while ( ! done ) { MockDirectoryWrapper dir = new MockDirectoryWrapper ( random , new org . apache . lucene . store . RAMDirectory ( startDir ) ) ; dir . setPreventDoubleWrite ( false ) ; IndexReader reader = IndexReader . open ( dir , false ) ; boolean success = false ; for ( int x = 0 ; x < 2 ; x ++ ) { double rate = 0.05 ; double diskRatio = ( ( double ) ( diskFree ) ) // diskUsage ; long thisDiskFree ; String testName ; if ( 0 == x ) { thisDiskFree = diskFree ; if ( diskRatio >= 2.0 ) { rate //= 2 ; } if ( diskRatio >= 4.0 ) { rate //= 2 ; } if ( diskRatio >= 6.0 ) { rate = 0.0 ; } if ( VERBOSE ) { System . out . println ( ( ( "\ncycle:<seq2seq4repair_space>" + diskFree ) + "<seq2seq4repair_space>bytes" ) ) ; } testName = ( "disk<seq2seq4repair_space>full<seq2seq4repair_space>during<seq2seq4repair_space>reader.close()<seq2seq4repair_space>@<seq2seq4repair_space>" + thisDiskFree ) + "<seq2seq4repair_space>bytes" ; } else { thisDiskFree = 0 ; rate = 0.0 ; if ( VERBOSE ) { System . out . println ( "\ncycle:<seq2seq4repair_space>same<seq2seq4repair_space>writer:<seq2seq4repair_space>unlimited<seq2seq4repair_space>disk<seq2seq4repair_space>space" ) ; } testName = "reader<seq2seq4repair_space>re-use<seq2seq4repair_space>after<seq2seq4repair_space>disk<seq2seq4repair_space>full" ; } dir . setMaxSizeInBytes ( thisDiskFree ) ; dir . setRandomIOExceptionRate ( rate ) ; try { if ( 0 == x ) { int docId = 12 ; for ( int i = 0 ; i < 13 ; i ++ ) { reader . deleteDocument ( docId ) ; <START_BUG> reader . setNorm ( docId , "contents" , ( ( float ) ( 2.0 ) ) ) ; <END_BUG> docId += 12 ; } } reader . close ( ) ; success = true ; if ( 0 == x ) { done = true ; } } catch ( IOException e ) { if ( VERBOSE ) { System . out . println ( ( "<seq2seq4repair_space>hit<seq2seq4repair_space>IOException:<seq2seq4repair_space>" + e ) ) ; e . printStackTrace ( System . out ) ; } err = e ; if ( 1 == x ) { e . printStackTrace ( ) ; fail ( ( testName + "<seq2seq4repair_space>hit<seq2seq4repair_space>IOException<seq2seq4repair_space>after<seq2seq4repair_space>disk<seq2seq4repair_space>space<seq2seq4repair_space>was<seq2seq4repair_space>freed<seq2seq4repair_space>up" ) ) ; } } IndexReader newReader = null ; try { newReader = IndexReader . open ( dir , false ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; fail ( ( ( testName + ":exception<seq2seq4repair_space>when<seq2seq4repair_space>creating<seq2seq4repair_space>IndexReader<seq2seq4repair_space>after<seq2seq4repair_space>disk<seq2seq4repair_space>full<seq2seq4repair_space>during<seq2seq4repair_space>close:<seq2seq4repair_space>" ) + e ) ) ; } IndexSearcher searcher = newSearcher ( newReader ) ; ScoreDoc [ ] hits = null ; try { hits = searcher . search ( new org . apache . lucene . search . TermQuery ( searchTerm ) , null , 1000 ) . scoreDocs ; } catch ( IOException e ) { e . printStackTrace ( ) ; fail ( ( ( testName + ":<seq2seq4repair_space>exception<seq2seq4repair_space>when<seq2seq4repair_space>searching:<seq2seq4repair_space>" ) + e ) ) ; } int result2 = hits . length ; if ( success ) { if ( result2 != END_COUNT ) { fail ( ( ( ( ( testName + ":<seq2seq4repair_space>method<seq2seq4repair_space>did<seq2seq4repair_space>not<seq2seq4repair_space>throw<seq2seq4repair_space>exception<seq2seq4repair_space>but<seq2seq4repair_space>hits.length<seq2seq4repair_space>for<seq2seq4repair_space>search<seq2seq4repair_space>on<seq2seq4repair_space>term<seq2seq4repair_space>'aaa'<seq2seq4repair_space>is<seq2seq4repair_space>" ) + result2 ) + "<seq2seq4repair_space>instead<seq2seq4repair_space>of<seq2seq4repair_space>expected<seq2seq4repair_space>" ) + END_COUNT ) ) ; } } else { if ( ( result2 != START_COUNT ) && ( result2 != END_COUNT ) ) { err . printStackTrace ( ) ; fail ( ( ( ( ( testName + ":<seq2seq4repair_space>method<seq2seq4repair_space>did<seq2seq4repair_space>throw<seq2seq4repair_space>exception<seq2seq4repair_space>but<seq2seq4repair_space>hits.length<seq2seq4repair_space>for<seq2seq4repair_space>search<seq2seq4repair_space>on<seq2seq4repair_space>term<seq2seq4repair_space>'aaa'<seq2seq4repair_space>is<seq2seq4repair_space>" ) + result2 ) + "<seq2seq4repair_space>instead<seq2seq4repair_space>of<seq2seq4repair_space>expected<seq2seq4repair_space>" ) + START_COUNT ) ) ; } } searcher . close ( ) ; newReader . close ( ) ; if ( result2 == END_COUNT ) { break ; } } dir . close ( ) ; diskFree += 10 ; }

Fix:
reader . setNorm ( docId , "content" , ( ( float ) ( 2.0 ) ) ) ;