Copied from Simplify Bloom Filters pull request.
There is no coverage of this branch. It is not possible. If this were true the bitMap[idx] in the main forEach loop would have thrown an array index out of bound exception. I think this can be removed. The final check to determine if the final upper bitmap does not set incorrect bits is valid.
Note: Even though the check is made that the upper bits have been set correctly, if they have not the exception is raised and the filter now has incorrect bits for the rest of its lifetime, i.e. no recovery is made and no flag is present in the filter to indicate the bits are bad. So you could then merge this into another filter and get the same exception, or record the bits to file and have bad bits in the recording, etc.
The same 'bug' is present in the SparseBloomFilter. It will raise an exception after merge if the TreeSet first or last position are outside the shape but not correct it.
I think these filters should attempt to clear any invalid bits before throwing exceptions. This makes them act as if they are a plain int of size nbits containing 0 or 1s. It should not be possible to put an index outside the range of the shape in the filter.