Skip to content

Use short-circuit && in Exchange.removeKeyRangeInternal (CodeQL java/non-short-circuit-evaluation)#245

Open
vharseko wants to merge 2 commits into
OpenIdentityPlatform:masterfrom
vharseko:features/codeql-non-short-circuit
Open

Use short-circuit && in Exchange.removeKeyRangeInternal (CodeQL java/non-short-circuit-evaluation)#245
vharseko wants to merge 2 commits into
OpenIdentityPlatform:masterfrom
vharseko:features/codeql-non-short-circuit

Conversation

@vharseko

@vharseko vharseko commented Jul 8, 2026

Copy link
Copy Markdown
Member

Summary

Resolves the java/non-short-circuit-evaluation alert in Exchange.

The anti-value guard used the non-short-circuit & operator:

if (removeOnlyAntiValue
    & !isKeyRangeAntiValue(lc._leftBuffer, lc._leftFoundAt, lc._rightBuffer, lc._rightFoundAt)) {

so isKeyRangeAntiValue(...) was evaluated even when removeOnlyAntiValue was
already false.

Fix

Switch to &&. isKeyRangeAntiValue only reads buffer state (key-block
offsets, right sibling, primordial-anti-value flag) and has no side effects, so
the change is behaviour-preserving — it merely skips the redundant call when
removeOnlyAntiValue is false.

Testing

mvn -o -pl persistit/core compile — BUILD SUCCESS.

…non-short-circuit-evaluation)

The anti-value guard combined removeOnlyAntiValue with the isKeyRangeAntiValue
check using the non-short-circuit & operator, so isKeyRangeAntiValue was always
evaluated even when removeOnlyAntiValue was false. isKeyRangeAntiValue only reads
buffer state and has no side effects, so switching to && is behaviour-preserving
and skips the redundant call when the flag is already false.
@vharseko vharseko requested a review from maximthomas July 8, 2026 14:55
@vharseko vharseko added codeql CodeQL static-analysis findings refactoring Code cleanup / refactoring, no behavior change labels Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codeql CodeQL static-analysis findings refactoring Code cleanup / refactoring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants