diff --git a/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextLiveDocsFormat.java b/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextLiveDocsFormat.java index f2ae9514974..a7d19d3613e 100644 --- a/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextLiveDocsFormat.java +++ b/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextLiveDocsFormat.java @@ -53,13 +53,13 @@ public class SimpleTextLiveDocsFormat extends LiveDocsFormat { @Override public MutableBits newLiveDocs(int size) throws IOException { - return new SimpleTextBits(size); + return new SimpleTextMutableBits(size); } @Override public MutableBits newLiveDocs(Bits existing) throws IOException { final SimpleTextBits bits = (SimpleTextBits) existing; - return bits.clone(); + return new SimpleTextMutableBits((BitSet)bits.bits.clone(), bits.size); } @Override @@ -144,16 +144,11 @@ public class SimpleTextLiveDocsFormat extends LiveDocsFormat { } } - static class SimpleTextBits implements MutableBits { + // read-only + static class SimpleTextBits implements Bits { final BitSet bits; final int size; - SimpleTextBits(int size) { - this.size = size; - bits = new BitSet(size); - bits.set(0, size); - } - SimpleTextBits(BitSet bits, int size) { this.bits = bits; this.size = size; @@ -168,16 +163,23 @@ public class SimpleTextLiveDocsFormat extends LiveDocsFormat { public int length() { return size; } + } + + // read-write + static class SimpleTextMutableBits extends SimpleTextBits implements MutableBits { + SimpleTextMutableBits(int size) { + this(new BitSet(size), size); + bits.set(0, size); + } + + SimpleTextMutableBits(BitSet bits, int size) { + super(bits, size); + } + @Override public void clear(int bit) { bits.clear(bit); } - - @Override - public SimpleTextBits clone() { - BitSet clonedBits = (BitSet) bits.clone(); - return new SimpleTextBits(clonedBits, size); - } } } diff --git a/lucene/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/src/java/org/apache/lucene/index/IndexWriter.java index 07418ad8465..68c7b3160af 100644 --- a/lucene/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/src/java/org/apache/lucene/index/IndexWriter.java @@ -417,7 +417,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { // docs, and it's copy-on-write (cloned whenever we need // to change it but it's been shared to an external NRT // reader). - public MutableBits liveDocs; + public Bits liveDocs; // How many further deletions we've done against // liveDocs vs when we loaded it or last wrote it: @@ -494,8 +494,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { if (reader == null) { reader = new SegmentReader(info, config.getReaderTermsIndexDivisor(), context); if (liveDocs == null) { - // nocommit: still don't like this cast, gotta be a cleaner way. - liveDocs = (MutableBits) reader.getLiveDocs(); + liveDocs = reader.getLiveDocs(); } //System.out.println("ADD seg=" + rld.info + " isMerge=" + isMerge + " " + readerMap.size() + " in pool"); } @@ -522,7 +521,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { } else { mergeReader = new SegmentReader(info, -1, context); if (liveDocs == null) { - liveDocs = (MutableBits) mergeReader.getLiveDocs(); + liveDocs = mergeReader.getLiveDocs(); } } } @@ -538,7 +537,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { assert !shared; final boolean didDelete = liveDocs.get(docID); if (didDelete) { - liveDocs.clear(docID); + ((MutableBits) liveDocs).clear(docID); pendingDeleteCount++; //System.out.println(" new del seg=" + info + " docID=" + docID + " pendingDelCount=" + pendingDeleteCount + " totDelCount=" + (info.docCount-liveDocs.count())); } @@ -627,7 +626,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { // until segments file is written: boolean success = false; try { - info.getCodec().liveDocsFormat().writeLiveDocs(liveDocs, dir, info, IOContext.DEFAULT); + info.getCodec().liveDocsFormat().writeLiveDocs((MutableBits)liveDocs, dir, info, IOContext.DEFAULT); success = true; } finally { if (!success) {