This is bad because you lose other unrelated documents in IndexWriter's buffer.
BytesRef v = null; // somehow my app screwed up
doc.add(new StoredField("foo", v));
Commit 1593580 from Robert Muir in branch 'dev/branches/lucene_solr_4_8'
[ https://svn.apache.org/r1593580 ]
LUCENE-5662: add missing null checks to Field to avoid aborting exceptions
Commit 1593579 from Robert Muir in branch 'dev/branches/branch_4x'
[ https://svn.apache.org/r1593579 ]
Commit 1593577 from Robert Muir in branch 'dev/trunk'
[ https://svn.apache.org/r1593577 ]
+1, awful this can lead to data loss!!
Here's a patch, adding/reusing byte was fine, because it would wrap it in a BytesRef, so you'd hit an implicit NPE.
BytesRef was unsafe both in the ctor and the reusing (setBytesRefValue).
String was only safe if you didnt reuse. setStringValue was missing a check.