Buggy code:
public class SimpleTextStoredFieldsWriter extends StoredFieldsWriter { private int numDocsWritten = 0 ; private final Directory directory ; private final String segment ; private IndexOutput out ; static final String FIELDS_EXTENSION = "fld" ; static final BytesRef TYPE_STRING = new BytesRef ( "string" ) ; static final BytesRef TYPE_BINARY = new BytesRef ( "binary" ) ; static final BytesRef TYPE_INT = new BytesRef ( "int" ) ; static final BytesRef TYPE_LONG = new BytesRef ( "long" ) ; static final BytesRef TYPE_FLOAT = new BytesRef ( "float" ) ; static final BytesRef TYPE_DOUBLE = new BytesRef ( "double" ) ; static final BytesRef END = new BytesRef ( "END" ) ; static final BytesRef DOC = new BytesRef ( "doc<seq2seq4repair_space>" ) ; static final BytesRef NUM = new BytesRef ( "<seq2seq4repair_space>numfields<seq2seq4repair_space>" ) ; static final BytesRef FIELD = new BytesRef ( "<seq2seq4repair_space>field<seq2seq4repair_space>" ) ; static final BytesRef NAME = new BytesRef ( "<seq2seq4repair_space>name<seq2seq4repair_space>" ) ; static final BytesRef TYPE = new BytesRef ( "<seq2seq4repair_space>type<seq2seq4repair_space>" ) ; static final BytesRef VALUE = new BytesRef ( "<seq2seq4repair_space>value<seq2seq4repair_space>" ) ; private final BytesRef scratch = new BytesRef ( ) ; public SimpleTextStoredFieldsWriter ( Directory directory , String segment , IOContext context ) throws IOException { } @ Override public void startDocument ( int numStoredFields ) throws IOException { } @ Override public void writeField ( FieldInfo info , IndexableField field ) throws IOException { write ( SimpleTextStoredFieldsWriter . FIELD ) ; write ( Integer . toString ( info . number ) ) ; newLine ( ) ; write ( SimpleTextStoredFieldsWriter . NAME ) ; write ( field . name ( ) ) ; newLine ( ) ; write ( SimpleTextStoredFieldsWriter . TYPE ) ; <START_BUG> final NumericField . DataType numericType = field . numericDataType ( ) ; <END_BUG> if ( numericType != null ) { switch ( numericType ) { case INT : write ( SimpleTextStoredFieldsWriter . TYPE_INT ) ; newLine ( ) ; write ( SimpleTextStoredFieldsWriter . VALUE ) ; write ( Integer . toString ( field . numericValue ( ) . intValue ( ) ) ) ; newLine ( ) ; break ; case LONG : write ( SimpleTextStoredFieldsWriter . TYPE_LONG ) ; newLine ( ) ; write ( SimpleTextStoredFieldsWriter . VALUE ) ; write ( Long . toString ( field . numericValue ( ) . longValue ( ) ) ) ; newLine ( ) ; break ; case FLOAT : write ( SimpleTextStoredFieldsWriter . TYPE_FLOAT ) ; newLine ( ) ; write ( SimpleTextStoredFieldsWriter . VALUE ) ; write ( Float . toString ( field . numericValue ( ) . floatValue ( ) ) ) ; newLine ( ) ; break ; case DOUBLE : write ( SimpleTextStoredFieldsWriter . TYPE_DOUBLE ) ; newLine ( ) ; write ( SimpleTextStoredFieldsWriter . VALUE ) ; write ( Double . toString ( field . numericValue ( ) . doubleValue ( ) ) ) ; newLine ( ) ; break ; default : assert false : "Should<seq2seq4repair_space>never<seq2seq4repair_space>get<seq2seq4repair_space>here" ; } } else { BytesRef bytes = field . binaryValue ( ) ; if ( bytes != null ) { write ( SimpleTextStoredFieldsWriter . TYPE_BINARY ) ; newLine ( ) ; write ( SimpleTextStoredFieldsWriter . VALUE ) ; write ( bytes ) ; newLine ( ) ; } else if ( ( field . stringValue ( ) ) == null ) { throw new IllegalArgumentException ( ( ( "field<seq2seq4repair_space>" + ( field . name ( ) ) ) + "<seq2seq4repair_space>is<seq2seq4repair_space>stored<seq2seq4repair_space>but<seq2seq4repair_space>does<seq2seq4repair_space>not<seq2seq4repair_space>have<seq2seq4repair_space>binaryValue,<seq2seq4repair_space>stringValue<seq2seq4repair_space>nor<seq2seq4repair_space>numericValue" ) ) ; } else { write ( SimpleTextStoredFieldsWriter . TYPE_STRING ) ; newLine ( ) ; write ( SimpleTextStoredFieldsWriter . VALUE ) ; write ( field . stringValue ( ) ) ; newLine ( ) ; } } } @ Override public void abort ( ) { } @ Override public void finish ( int numDocs ) throws IOException { } @ Override public void close ( ) throws IOException { } private void write ( String s ) throws IOException { } private void write ( BytesRef bytes ) throws IOException { } private void newLine ( ) throws IOException { } }

Fix:
final NumericField . DataType numericType = field . fieldType ( ) . numericType ( ) ;