Skip to content

Unbox Boolean operands of &&, ||, and a boolean conditional expression - #8520

Open
mernst wants to merge 258 commits into
typetools:masterfrom
mernst:conditional-and-or-unboxing
Open

mernst wants to merge 258 commits into
typetools:masterfrom
mernst:conditional-and-or-unboxing

Conversation

@mernst

@mernst mernst commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Land after #8400.
Land before #8399.

The CFG now unboxes Boolean operands of && and ||, and a Boolean operand of a conditional expression whose type is boolean, as in flag ? aBoolean : false, as it does in other unboxing contexts. Therefore, the Nullness Checker refines such an operand to non-null after the operand is evaluated. The new tests are checker/tests/nullness/ConditionalAndOrUnboxing.java and checker/tests/nullness/ConditionalExpressionUnboxing.java.

This pull request was split out of #8399, so that it need not wait for #8329. #8399 keeps the tests of operands whose type is a type variable bounded by Boolean, which need #8329.

🤖 Generated with Claude Code

mernst added 30 commits October 22, 2026 21:18
The default transfer function now merges the then-store and else-store of
its input, which describe an earlier node.  Only nodes whose input stores
describe the node itself keep them: casts, markers, `&&`, `||`, `!`,
ternary expressions, and return statements.  This fixes unsoundness for
`instanceof`, string concatenation, lambdas, array creation, and other
node kinds that passed an operand's stores through.

`==`, `!=`, `&`, `|`, and `^` derive their stores from a truth table, which
also handles a constant operand.  A boolean literal passes its input's
stores along only when it is the right operand of such an operator, as
determined from the CFG rather than the AST.

JointJavacJavaParserVisitor: add asserts that the type checkers now need.
…al path is unchanged

Annotate moreSpecificValue, which accepts and may return null.
Now that most nodes merge the then-store and else-store of their input, the
method access in isNN(o).booleanValue() must pass them along to the unboxing call.
…s' into explicit-unboxing-keeps-conditional-stores
Subclasses such as NonEmptyTransfer refine a result's then-store and
else-store in place, which requires two distinct stores.
…s' into explicit-unboxing-keeps-conditional-stores
…s' into explicit-unboxing-keeps-conditional-stores
…into explicit-unboxing-keeps-conditional-stores
…s' into explicit-unboxing-keeps-conditional-stores
…k-branch-master into conditional-stores-of-operands
…h/types/checker-framework-fork-mernst-branch-conditional-stores-of-operands into unboxing-keeps-conditional-stores
# Conflicts:
#	framework/src/main/java/org/checkerframework/framework/flow/CFAbstractTransfer.java
…actory; pass a non-null else-store

Since typetools#8607, the CFG does not mark an enhanced for loop's boxing or unboxing conversion with the
iterable expression, so the branches are dead.  Their tests and the UnboxingWeakens test checker move
to typetools#8607.  processPostconditions passes its store as both stores, because an unconditional
postcondition refines only the then-store.
…ditional-stores

# Conflicts:
#	docs/CHANGELOG.md
…nditional-stores

# Conflicts:
#	framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java
…lean

Co-authored-by: Michael Ernst <mernst@cs.washington.edu>
@mernst mernst changed the title Unbox Boolean operands of && and || Unbox Boolean operands of &&, ||, and a boolean conditional expression Nov 29, 2026
mernst added a commit to mernst/checker-framework that referenced this pull request Nov 29, 2026
@mernst

mernst commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants