salvatore-campagna commented on code in PR #16623:
URL: https://github.com/apache/lucene/pull/16623#discussion_r4166899663
##########
lucene/core/src/java/org/apache/lucene/util/DenseLiveDocs.java:
##########
@@ -182,6 +182,11 @@ public int deletedCount() {
return deletedCount;
}
+ @Override
+ public FixedBitSet toFixedBitSet() {
+ return liveDocs.clone();
Review Comment:
`clone()` keeps `liveDocs.length()`, but this instance's `length()` is
`maxDoc`, and the constructor only asserts `liveDocs.length() >= maxDoc`.
I wrote a test to reproduce a possible issue that happens when the backing
bit set is longer than `maxDoc`:
```java
public void testCopyOfPaddedDenseLiveDocsPreservesLength() {
int maxDoc = 100;
// DenseLiveDocs only requires liveDocs.length() >= maxDoc (see
constructor)
FixedBitSet backing = new FixedBitSet(256);
backing.set(0, maxDoc);
backing.clear(7);
DenseLiveDocs dense = DenseLiveDocs.builder(backing, maxDoc).build();
assertEquals(maxDoc, dense.length());
FixedBitSet copy = FixedBitSet.copyOf(dense);
assertEquals(dense.length(), copy.length());
assertEquals(dense.length() - dense.deletedCount(), copy.cardinality());
}
```
The first assertion fails with `expected:<100> but was:<256>`, the
cardinality one passes. The copy then claims 256 docs for a 100 doc segment,
which trips the `assert liveDocs.length() == info.info.maxDoc()` in
`PendingDeletes#writeLiveDocs`. Not reachable through `Lucene90LiveDocsFormat`
today, which always passes `new FixedBitSet(data, maxDoc)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]