Skip to content

Apache Lucene open-source search software

LUCENE-3032: TestIndexWriterException fails with NPE on realtime

Simon Willnauerf90bf1aee85f
diff --git a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
index d67fe95d560..b94fb24f101 100644
--- a/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
+++ b/lucene/src/java/org/apache/lucene/index/DocumentsWriterPerThread.java
@@ -325,9 +325,13 @@ public class DocumentsWriterPerThread {
FrozenBufferedDeletes prepareFlush() {
assert numDocsInRAM > 0;
final FrozenBufferedDeletes globalDeletes = deleteQueue.freezeGlobalBuffer(deleteSlice);
- // apply all deletes before we flush and release the delete slice
- deleteSlice.apply(pendingDeletes, numDocsInRAM);
- deleteSlice = null;
+ /* deleteSlice can possibly be null if we have hit non-aborting exceptions during indexing and never succeeded
+ adding a document. */
+ if (deleteSlice != null) {
+ // apply all deletes before we flush and release the delete slice
+ deleteSlice.apply(pendingDeletes, numDocsInRAM);
+ deleteSlice = null;
+ }
return globalDeletes;
}