Buggy code:
public static final String TEST_DIRECTORY = System . getProperty ( "tests.directory" , "random" ) ; public static final int TEST_ITER = Integer . parseInt ( System . getProperty ( "tests.iter" , "1" ) ) ; public static final int TEST_ITER_MIN = Integer . parseInt ( System . getProperty ( "tests.iter.min" , Integer . toString ( LuceneTestCase . TEST_ITER ) ) ) ; public static final String TEST_SEED = System . getProperty ( "tests.seed" , "random" ) ; public static final boolean TEST_NIGHTLY = Boolean . parseBoolean ( System . getProperty ( "tests.nightly" , "false" ) ) ; public static final String TEST_LINE_DOCS_FILE = System . getProperty ( "tests.linedocsfile" , "europarl.lines.txt.gz" ) ; public static final String TEST_CLEAN_THREADS = System . getProperty ( "tests.cleanthreads" , "perClass" ) ; public static final Throttling TEST_THROTTLING = ( LuceneTestCase . TEST_NIGHTLY ) ? Throttling . SOMETIMES : Throttling . NEVER ; private static final Pattern codecWithParam = Pattern . compile ( "(.*)\\(\\s*(\\d+)\\s*\\)" ) ; public static final int RANDOM_MULTIPLIER = Integer . parseInt ( System . getProperty ( "tests.multiplier" , "1" ) ) ; public static boolean PREFLEX_IMPERSONATION_IS_ACTIVE ; private int savedBoolMaxClauseCount = BooleanQuery . getMaxClauseCount ( ) ; private volatile Thread . UncaughtExceptionHandler savedUncaughtExceptionHandler = null ; private static LuceneTestCase . State state = LuceneTestCase . State . INITIAL ; private static enum State { INITIAL , SETUP , RANTEST , TEARDOWN ; } public static SegmentReader getOnlySegmentReader ( IndexReader reader ) { } private static class UncaughtExceptionEntry { public final Thread thread ; public final Throwable exception ; public UncaughtExceptionEntry ( Thread thread , Throwable exception ) { } } private List < LuceneTestCase . UncaughtExceptionEntry > uncaughtExceptions = Collections . synchronizedList ( new ArrayList < LuceneTestCase . UncaughtExceptionEntry > ( ) ) ; private static Codec savedCodec ; private static InfoStream savedInfoStream ; private static SimilarityProvider similarityProvider ; private static Locale locale ; private static Locale savedLocale ; private static TimeZone timeZone ; private static TimeZone savedTimeZone ; protected static Map < MockDirectoryWrapper , StackTraceElement [ ] > stores ; @ Deprecated static List < String > testClassesRun = new ArrayList < String > ( ) ; private static void initRandom ( ) { } @ Deprecated private static boolean icuTested = false ; @ BeforeClass public static void beforeClassLuceneTestCaseJ4 ( ) { LuceneTestCase . initRandom ( ) ; LuceneTestCase . state = LuceneTestCase . State . INITIAL ; LuceneTestCase . tempDirs . clear ( ) ; LuceneTestCase . stores = Collections . synchronizedMap ( new IdentityHashMap < MockDirectoryWrapper , StackTraceElement [ ] > ( ) ) ; if ( ( System . getProperty ( "solr.directoryFactory" ) ) == null ) { System . setProperty ( "solr.directoryFactory" , "org.apache.solr.core.MockDirectoryFactory" ) ; } if ( LuceneTestCase . VERBOSE ) { Set < String > codecs = Codec . availableCodecs ( ) ; for ( String codec : codecs ) { System . out . println ( ( ( ( "Loaded<seq2seq4repair_space>codec:<seq2seq4repair_space>'" + codec ) + "':<seq2seq4repair_space>" ) + ( Codec . forName ( codec ) . getClass ( ) . getName ( ) ) ) ) ; } Set < String > postingsFormats = PostingsFormat . availablePostingsFormats ( ) ; for ( String postingsFormat : postingsFormats ) { System . out . println ( ( ( ( "Loaded<seq2seq4repair_space>postingsFormat:<seq2seq4repair_space>'" + postingsFormat ) + "':<seq2seq4repair_space>" ) + ( PostingsFormat . forName ( postingsFormat ) . getClass ( ) . getName ( ) ) ) ) ; } } LuceneTestCase . savedInfoStream = InfoStream . getDefault ( ) ; if ( LuceneTestCase . INFOSTREAM ) { LuceneTestCase . random . nextBoolean ( ) ; InfoStream . setDefault ( new PrintStreamInfoStream ( System . out ) ) ; } else { if ( LuceneTestCase . random . nextBoolean ( ) ) { InfoStream . setDefault ( new NullInfoStream ( ) ) ; } } LuceneTestCase . PREFLEX_IMPERSONATION_IS_ACTIVE = false ; LuceneTestCase . savedCodec = Codec . getDefault ( ) ; final Codec codec ; int randomVal = LuceneTestCase . random . nextInt ( 10 ) ; <START_BUG> if ( ( "Lucene3x" . equals ( LuceneTestCase . TEST_CODEC ) ) || ( ( "random" . equals ( LuceneTestCase . TEST_CODEC ) ) && ( randomVal <= 3 ) ) ) { <END_BUG> codec = new PreFlexRWCodec ( ) ; LuceneTestCase . PREFLEX_IMPERSONATION_IS_ACTIVE = true ; } else if ( ( "SimpleText" . equals ( LuceneTestCase . TEST_CODEC ) ) || ( ( "random" . equals ( LuceneTestCase . TEST_CODEC ) ) && ( randomVal == 9 ) ) ) { codec = new SimpleTextCodec ( ) ; } else if ( ! ( "random" . equals ( LuceneTestCase . TEST_CODEC ) ) ) { codec = Codec . forName ( LuceneTestCase . TEST_CODEC ) ; } else if ( "random" . equals ( LuceneTestCase . TEST_POSTINGSFORMAT ) ) { codec = new RandomCodec ( LuceneTestCase . random , LuceneTestCase . useNoMemoryExpensiveCodec ) ; } else { codec = new Lucene40Codec ( ) { private final PostingsFormat format = PostingsFormat . forName ( LuceneTestCase . TEST_POSTINGSFORMAT ) ; @ Override public PostingsFormat getPostingsFormatForField ( String field ) { return format ; } @ Override public String toString ( ) { return ( ( super . toString ( ) ) + ":<seq2seq4repair_space>" ) + ( format . toString ( ) ) ; } } ; } Codec . setDefault ( codec ) ; LuceneTestCase . savedLocale = Locale . getDefault ( ) ; if ( ! ( LuceneTestCase . icuTested ) ) { LuceneTestCase . icuTested = true ; try { Locale . setDefault ( Locale . US ) ; Class . forName ( "com.ibm.icu.util.ULocale" ) ; } catch ( ClassNotFoundException cnfe ) { } } LuceneTestCase . locale = ( LuceneTestCase . TEST_LOCALE . equals ( "random" ) ) ? LuceneTestCase . randomLocale ( LuceneTestCase . random ) : LuceneTestCase . localeForName ( LuceneTestCase . TEST_LOCALE ) ; Locale . setDefault ( LuceneTestCase . locale ) ; LuceneTestCase . savedTimeZone = TimeZone . getDefault ( ) ;

Fix:
if ( ( "Lucene3x" . equals ( LuceneTestCase . TEST_CODEC ) ) || ( ( "random" . equals ( LuceneTestCase . TEST_CODEC ) ) && ( randomVal < 2 ) ) ) {