Buggy code:
class DocHelper { public static final String FIELD_1_TEXT = "field<seq2seq4repair_space>one<seq2seq4repair_space>text" ; public static final String TEXT_FIELD_1_KEY = "textField1" ; public static Field textField1 = new Field ( DocHelper . TEXT_FIELD_1_KEY , DocHelper . FIELD_1_TEXT , Store . YES , Index . TOKENIZED , TermVector . NO ) ; public static final String FIELD_2_TEXT = "field<seq2seq4repair_space>field<seq2seq4repair_space>field<seq2seq4repair_space>two<seq2seq4repair_space>text" ; public static final int [ ] FIELD_2_FREQS = new int [ ] { 3 , 1 , 1 } ; public static final String TEXT_FIELD_2_KEY = "textField2" ; public static Field textField2 = new Field ( DocHelper . TEXT_FIELD_2_KEY , DocHelper . FIELD_2_TEXT , Store . YES , Index . TOKENIZED , TermVector . WITH_POSITIONS_OFFSETS ) ; public static final String FIELD_2_COMPRESSED_TEXT = "field<seq2seq4repair_space>field<seq2seq4repair_space>field<seq2seq4repair_space>two<seq2seq4repair_space>text" ; public static final int [ ] COMPRESSED_FIELD_2_FREQS = new int [ ] { 3 , 1 , 1 } ; public static final String COMPRESSED_TEXT_FIELD_2_KEY = "compressedTextField2" ; public static Field compressedTextField2 = new Field ( DocHelper . COMPRESSED_TEXT_FIELD_2_KEY , DocHelper . FIELD_2_COMPRESSED_TEXT , Store . COMPRESS , Index . TOKENIZED , TermVector . WITH_POSITIONS_OFFSETS ) ; public static final String FIELD_3_TEXT = "aaaNoNorms<seq2seq4repair_space>aaaNoNorms<seq2seq4repair_space>bbbNoNorms" ; public static final String TEXT_FIELD_3_KEY = "textField3" ; public static Field textField3 = new Field ( DocHelper . TEXT_FIELD_3_KEY , DocHelper . FIELD_3_TEXT , Store . YES , Index . TOKENIZED ) ; public static final String KEYWORD_TEXT = "Keyword" ; public static final String KEYWORD_FIELD_KEY = "keyField" ; public static Field keyField = new Field ( DocHelper . KEYWORD_FIELD_KEY , DocHelper . KEYWORD_TEXT , Store . YES , Index . UN_TOKENIZED ) ; public static final String NO_NORMS_TEXT = "omitNormsText" ; public static final String NO_NORMS_KEY = "omitNorms" ; public static Field noNormsField = new Field ( DocHelper . NO_NORMS_KEY , DocHelper . NO_NORMS_TEXT , Store . YES , Index . NO_NORMS ) ; public static final String UNINDEXED_FIELD_TEXT = "unindexed<seq2seq4repair_space>field<seq2seq4repair_space>text" ; public static final String UNINDEXED_FIELD_KEY = "unIndField" ; public static Field unIndField = new Field ( DocHelper . UNINDEXED_FIELD_KEY , DocHelper . UNINDEXED_FIELD_TEXT , Store . YES , Index . NO ) ; public static final String UNSTORED_1_FIELD_TEXT = "unstored<seq2seq4repair_space>field<seq2seq4repair_space>text" ; public static final String UNSTORED_FIELD_1_KEY = "unStoredField1" ; public static Field unStoredField1 = new Field ( DocHelper . UNSTORED_FIELD_1_KEY , DocHelper . UNSTORED_1_FIELD_TEXT , Store . NO , Index . TOKENIZED , TermVector . NO ) ; public static final String UNSTORED_2_FIELD_TEXT = "unstored<seq2seq4repair_space>field<seq2seq4repair_space>text" ; public static final String UNSTORED_FIELD_2_KEY = "unStoredField2" ; public static Field unStoredField2 = new Field ( DocHelper . UNSTORED_FIELD_2_KEY , DocHelper . UNSTORED_2_FIELD_TEXT , Store . NO , Index . TOKENIZED , TermVector . YES ) ; public static final String LAZY_FIELD_BINARY_KEY = "lazyFieldBinary" ; public static byte [ ] LAZY_FIELD_BINARY_BYTES ; public static Field lazyFieldBinary ; public static final String LAZY_FIELD_KEY = "lazyField" ; public static final String LAZY_FIELD_TEXT = "These<seq2seq4repair_space>are<seq2seq4repair_space>some<seq2seq4repair_space>field<seq2seq4repair_space>bytes" ; public static Field lazyField = new Field ( DocHelper . LAZY_FIELD_KEY , DocHelper . LAZY_FIELD_TEXT , Store . YES , Index . TOKENIZED ) ; public static final String LARGE_LAZY_FIELD_KEY = "largeLazyField" ; public static String LARGE_LAZY_FIELD_TEXT ; public static Field largeLazyField ; public static final String FIELD_UTF1_TEXT = "field<seq2seq4repair_space>one<seq2seq4repair_space>一text" ; public static final String TEXT_FIELD_UTF1_KEY = "textField1Utf8" ; public static Field textUtfField1 = new Field ( DocHelper . TEXT_FIELD_UTF1_KEY , DocHelper . FIELD_UTF1_TEXT , Store . YES , Index . TOKENIZED , TermVector . NO ) ; public static final String FIELD_UTF2_TEXT = "field<seq2seq4repair_space>field<seq2seq4repair_space>field<seq2seq4repair_space>一two<seq2seq4repair_space>text" ; public static final int [ ] FIELD_UTF2_FREQS = new int [ ] { 3 , 1 , 1 } ; public static final String TEXT_FIELD_UTF2_KEY = "textField2Utf8" ; public static Field textUtfField2 = new Field ( DocHelper . TEXT_FIELD_UTF2_KEY , DocHelper . FIELD_UTF2_TEXT , Store . YES , Index . TOKENIZED , TermVector . WITH_POSITIONS_OFFSETS ) ; public static Map nameValues = null ; public static Field [ ] fields = new Field [ ] { DocHelper . textField1 , DocHelper . textField2 , DocHelper . textField3 , DocHelper . compressedTextField2 , DocHelper . keyField , DocHelper . noNormsField , DocHelper . unIndField , DocHelper . unStoredField1 , DocHelper . unStoredField2 , DocHelper . textUtfField1 , DocHelper . textUtfField2 , DocHelper . lazyField , DocHelper . lazyFieldBinary , DocHelper . largeLazyField } ; public static Map all = new HashMap ( ) ; public static Map indexed = new HashMap ( ) ; public static Map stored = new HashMap ( ) ; public static Map unstored = new HashMap ( ) ; public static Map unindexed = new HashMap ( ) ; public static Map termvector = new HashMap ( ) ; public static Map notermvector = new HashMap ( ) ; public static Map lazy = new HashMap ( ) ; public static Map noNorms = new HashMap ( ) ; private static void add ( Map map , Fieldable field ) { } public static void setupDoc ( Document doc ) { } public static SegmentInfo writeDoc ( Directory dir , Document doc ) throws IOException { } public static SegmentInfo writeDoc ( Directory dir , Analyzer analyzer , Similarity similarity , Document doc ) throws IOException { IndexWriter writer = new IndexWriter ( dir , analyzer ) ; writer . setSimilarity ( similarity ) ; writer . addDocument ( doc ) ; writer . flush ( ) ; <START_BUG> SegmentInfo info = writer . segmentInfos . info ( ( ( writer . segmentInfos . size ( ) ) - 1 ) ) ; <END_BUG> writer . close ( ) ; return info ; } public static int numFields ( Document doc ) { } }

Fix:
SegmentInfo info = writer . newestSegment ( ) ;