Fix CodeQL useless-comparison alert in XorFilter construction loop Hoist the construction-failure throw out of the peeling loop so the loop can terminate through its own bound. Previously the last iteration always exited via break or throw, making the 'attempt < MAX_ITERATIONS' condition provably always-true (CodeQL java/constant-comparison). Behavior is unchanged; the success check now runs after the loop. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
diff --git a/src/main/java/org/apache/datasketches/filters/xorfilter/XorFilter.java b/src/main/java/org/apache/datasketches/filters/xorfilter/XorFilter.java index 5c48eeb..96ffb4f 100644 --- a/src/main/java/org/apache/datasketches/filters/xorfilter/XorFilter.java +++ b/src/main/java/org/apache/datasketches/filters/xorfilter/XorFilter.java
@@ -131,10 +131,10 @@ buildSeed = splitMix64(rngState); stackSize = map(keys, numKeys, buildSeed, xorMask, count, queue, stackHash, stackIndex); if (stackSize == numKeys) { break; } - if (attempt == (MAX_ITERATIONS - 1)) { - throw new SketchesArgumentException("Xor filter construction failed after " + MAX_ITERATIONS - + " attempts; the input likely contains duplicate keys or is degenerate."); - } + } + if (stackSize != numKeys) { + throw new SketchesArgumentException("Xor filter construction failed after " + MAX_ITERATIONS + + " attempts; the input likely contains duplicate keys or is degenerate."); } seed_ = buildSeed;