Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
6d90e27
Keep conditional facts across a synthetic unboxing call
mernst Oct 22, 2026
1029cb8
Mark unboxing calls in the CFG; treat every unboxing call alike in th…
mernst Oct 22, 2026
14ad323
Do not treat an operand's conditional stores as those of an enclosing…
mernst Oct 23, 2026
288f084
Treat an explicit call to booleanValue() like an implicit unboxing
mernst Oct 23, 2026
3f550a0
Merge branch 'conditional-stores-of-operands' of github.com:mernst/ch…
mernst Oct 23, 2026
4e4bd45
Share the unboxing path with the general method-invocation path; test…
mernst Oct 23, 2026
1f1d2f7
Merge branch 'master' into conditional-stores-of-operands
mernst Oct 23, 2026
4933430
Merge branch 'conditional-stores-of-operands' into unboxing-keeps-con…
mernst Oct 23, 2026
8534341
Merge branch 'unboxing-keeps-conditional-stores' into explicit-unboxi…
mernst Oct 23, 2026
60653f5
Merge conditional stores by default; refine them for boolean operators
mernst Oct 23, 2026
09b59b5
Move the unboxing transfer function into its own method, so the gener…
mernst Oct 23, 2026
01d6ab6
Merge remote-tracking branch 'origin/conditional-stores-of-operands' …
mernst Oct 23, 2026
a1024d8
Keep the conditional stores at the target of an unboxing call
mernst Oct 23, 2026
4535ce4
Merge remote-tracking branch 'origin/unboxing-keeps-conditional-store…
mernst Oct 23, 2026
862e58b
createTransferResult: keep two (equal) stores when the input has two
mernst Oct 23, 2026
45810a0
Merge branch 'master' into conditional-stores-of-operands
mernst Oct 24, 2026
125627a
Merge branch 'conditional-stores-of-operands' into unboxing-keeps-con…
mernst Oct 24, 2026
b774035
Merge remote-tracking branch 'upstream/master' into explicit-unboxing…
mernst Oct 27, 2026
ff55d4e
Merge remote-tracking branch 'upstream/master' into unboxing-keeps-co…
mernst Oct 27, 2026
9bc9770
Merge remote-tracking branch 'origin/unboxing-keeps-conditional-store…
mernst Oct 27, 2026
704c420
JointJavacJavaParserVisitor: assert that an Optional is present befor…
mernst Oct 27, 2026
229f6a7
Address review findings: tree-based operand check, single lambda-resu…
mernst Oct 27, 2026
3919420
Merge branch 'master' into ajava-optional-asserts
mernst Oct 27, 2026
49abdc9
Merge branch 'ajava-optional-asserts' into conditional-stores-of-oper…
mernst Oct 27, 2026
6a4bcae
Merge branch 'conditional-stores-of-operands' into unboxing-keeps-con…
mernst Oct 27, 2026
fee0a0f
Restore imports that isTargetOfUnboxingCall uses
mernst Oct 27, 2026
dc718d2
Merge remote-tracking branch 'origin/unboxing-keeps-conditional-store…
mernst Oct 27, 2026
380fe28
Suppress interning warning for reference equality of trees
mernst Oct 27, 2026
92c2817
Merge remote-tracking branch 'origin/conditional-stores-of-operands' …
mernst Oct 27, 2026
40470a7
Merge remote-tracking branch 'origin/conditional-stores-of-operands' …
mernst Oct 27, 2026
d2e4388
Merge remote-tracking branch 'origin/unboxing-keeps-conditional-store…
mernst Oct 27, 2026
a9bb8e8
Merge branch 'master' of /home/mernst/research/types/checker-framewor…
mernst Oct 28, 2026
01311f7
Merge branch 'conditional-stores-of-operands' of /home/mernst/researc…
mernst Oct 28, 2026
5b3a221
Merge branch 'master' into unboxing-keeps-conditional-stores
mernst Oct 28, 2026
1cdf5cd
Merge branch 'unboxing-keeps-conditional-stores' into explicit-unboxi…
mernst Oct 28, 2026
4e24e89
Merge branch 'master' into conditional-stores-of-operands
mernst Oct 29, 2026
1fdb4e0
Merge branch 'conditional-stores-of-operands' into unboxing-keeps-con…
mernst Oct 29, 2026
22f10ac
Merge branch 'unboxing-keeps-conditional-stores' into explicit-unboxi…
mernst Oct 29, 2026
7bba3e0
Merge remote-tracking branch 'upstream/master' into conditional-store…
mernst Oct 30, 2026
bc75694
Improve comments
mernst Oct 30, 2026
86e3b0d
Improve documentation of createTransferResult and related methods; ad…
mernst Oct 30, 2026
1264a0e
Precision
mernst Oct 30, 2026
bc95d4c
Merge branch 'master' into conditional-stores-of-operands
mernst Oct 31, 2026
a90cc0a
Merge branch 'master' into conditional-stores-of-operands
mernst Nov 1, 2026
ef3b95e
Merge branch 'conditional-stores-of-operands' into unboxing-keeps-con…
mernst Nov 1, 2026
6ece119
Look through unboxing calls in isConstantBoolean; update visitUnboxin…
mernst Nov 3, 2026
699f2aa
Check receiver type before scanning block for unboxing call
mernst Nov 3, 2026
d972699
Don't refine == of two boxed operands; see through unboxing in isCons…
mernst Nov 3, 2026
b833d67
Merge branch 'master' into conditional-stores-of-operands
mernst Nov 7, 2026
30e13fc
Merge branch 'conditional-stores-of-operands' into unboxing-keeps-con…
mernst Nov 7, 2026
7df5cd8
Merge branch 'unboxing-keeps-conditional-stores' into explicit-unboxi…
mernst Nov 7, 2026
7e5be39
Rename the parameter of visitConditionalNot to `in`
mernst Nov 8, 2026
d967709
Clarify the comment about skipping the least upper bound of equal stores
mernst Nov 8, 2026
cb355dc
Merge branch 'conditional-stores-of-operands' of /home/mernst/researc…
mernst Nov 8, 2026
1d4a6ea
Merge branch 'unboxing-keeps-conditional-stores' of /home/mernst/rese…
mernst Nov 8, 2026
c1d64f5
createTransferResult: keep the result's stores distinct when the inpu…
mernst Nov 8, 2026
a6dc353
Merge branch 'conditional-stores-of-operands' of ../checker-framework…
mernst Nov 8, 2026
ae906fd
Changelog: visitMethodAccess() skips visitNode() only when the input …
mernst Nov 8, 2026
ef88081
Test | with a negated boxed constant operand (moved from #8404)
mernst Nov 8, 2026
159dd13
Merge branch 'unboxing-keeps-conditional-stores' of ../checker-framew…
mernst Nov 8, 2026
3883ea3
Drop removeCastsAndUnboxing, which duplicates isConstantBoolean's unb…
mernst Nov 8, 2026
e466218
Do not refine == or != with two boxed operands, which Java compares b…
mernst Nov 8, 2026
928ca54
Merge branch 'conditional-stores-of-operands' into unboxing-keeps-con…
mernst Nov 8, 2026
05a8bbf
Move tests of Boolean operands of |, ^, and == here from #8399
mernst Nov 8, 2026
390bd7e
Merge branch 'unboxing-keeps-conditional-stores' into explicit-unboxi…
mernst Nov 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 285 additions & 0 deletions checker/tests/nullness/ConditionalStoresOfOperands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
// Test that an operator does not treat the facts that hold when one operand is true or false as
// facts that hold when the operator's result is true or false.

import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import org.checkerframework.checker.nullness.qual.Nullable;

public class ConditionalStoresOfOperands {

@EnsuresNonNullIf(expression = "#1", result = true)
static boolean isNN(@Nullable Object o) {
return o != null;
}

@EnsuresNonNullIf(expression = "#1", result = false)
static boolean isNull(@Nullable Object o) {
return o == null;
}

void orLiteral(@Nullable Object o) {
if (isNN(o) | true) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void orRight(@Nullable Object o, boolean b) {
if (b | isNN(o)) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void orRightElse(@Nullable Object o, boolean b) {
if (b | isNull(o)) {
} else {
o.hashCode();
}
}

void andRight(@Nullable Object o, boolean b) {
if (b & isNN(o)) {
o.hashCode();
} else {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void xorLiteral(@Nullable Object o) {
if (isNN(o) ^ true) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void equalToVariable(@Nullable Object o, boolean b) {
if (b == isNN(o)) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void notEqualToVariable(@Nullable Object o, boolean b) {
if (b != isNN(o)) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void equalToComparison(@Nullable Object o) {
if (isNN(o) == (2 < 1)) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void equalToString(@Nullable Object o) {
if ("x" == (isNN(o) + "")) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void equalToNegatedTrue(@Nullable Object o) {
if (isNN(o) == !true) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void equalToTrue(@Nullable Object o) {
if (isNN(o) == true) {
o.hashCode();
}
}

void equalToFalse(@Nullable Object o) {
if (isNN(o) == false) {
return;
}
o.hashCode();
}

void equalToNegatedFalse(@Nullable Object o) {
if (isNN(o) == !false) {
o.hashCode();
}
}

void notEqualToNegatedTrue(@Nullable Object o) {
if (isNN(o) != !true) {
o.hashCode();
}
}

void trueEqualTo(@Nullable Object o) {
if (true == isNN(o)) {
o.hashCode();
}
}

void andIsNull(@Nullable Object o, boolean b) {
if (b & isNull(o)) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void trueAnd(@Nullable Object o) {
if (true & isNN(o)) {
o.hashCode();
}
}

void andTrue(@Nullable Object o) {
if (isNN(o) & true) {
o.hashCode();
}
}

void orFalse(@Nullable Object o) {
if (isNN(o) | false) {
o.hashCode();
}
}

void xorFalse(@Nullable Object o) {
if (isNN(o) ^ false) {
o.hashCode();
}
}

void xorTrueElse(@Nullable Object o) {
if (isNN(o) ^ true) {
} else {
o.hashCode();
}
}

// The then-branch is unreachable, so any store is sound there.
void andFalseUnreachable(@Nullable Object o) {
if (isNN(o) & false) {
o.hashCode();
}
}

void falseAndUnreachable(@Nullable Object o) {
if (false & isNN(o)) {
o.hashCode();
}
}

void equalToCastTrue(@Nullable Object o) {
if (isNN(o) == (boolean) true) {
o.hashCode();
}
}

void falseNotEqualTo(@Nullable Object o) {
if (false != isNN(o)) {
o.hashCode();
}
}

void notEqualToFalse(@Nullable Object o) {
if (isNN(o) != false) {
o.hashCode();
}
}

void instanceOfLambda(@Nullable Object o) {
if (isNN(o) | !(((Runnable) () -> {}) instanceof Runnable)) {
} else {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void instanceOfArrayCreation(@Nullable Object o) {
if (isNN(o) | !(new Object[] {} instanceof Object[])) {
} else {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void instanceOfStringConcatenation(@Nullable Object o, @Nullable Object p) {
if (isNN(o) | !(("" + isNN(p)) instanceof String)) {
} else {
// :: error: [dereference.of.nullable]
p.hashCode();
}
}

void instanceOfInConditionalAnd(@Nullable Object o) {
// :: error: [dereference.of.nullable]
if (("" + isNN(o)) instanceof String && o.hashCode() == 0) {}
}

void conditionalAnd(@Nullable Object o, boolean b) {
if (b && isNN(o)) {
o.hashCode();
}
}

void conditionalOrElse(@Nullable Object o, boolean b) {
if (b || isNull(o)) {
} else {
o.hashCode();
}
}

void castToBoolean(@Nullable Object o) {
if ((boolean) isNN(o)) {
o.hashCode();
}
}

void ternary(@Nullable Object o, boolean b) {
if (b ? isNN(o) : isNN(o)) {
o.hashCode();
}
}

@EnsuresNonNullIf(expression = "#1", result = true)
static Boolean isNNBoxed(@Nullable Object o) {
return o != null;
}

// Java compares two boxed operands of == and != by reference, so their values might be equal
// even when the comparison is false. isNNBoxed might return a Boolean that is not Boolean.TRUE.

void equalToBothBoxed(@Nullable Object o) {
if (isNNBoxed(o) == (Boolean) false) {
// :: error: [dereference.of.nullable]
o.hashCode();
} else {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

void notEqualBothBoxed(@Nullable Object o) {
if (isNNBoxed(o) != (Boolean) false) {
// :: error: [dereference.of.nullable]
o.hashCode();
}
}

@EnsuresNonNullIf(expression = "#1", result = true)
static boolean returnsIsNN(@Nullable Object o) {
return isNN(o);
}

@EnsuresNonNullIf(expression = "#1", result = true)
static boolean returnsEqualToTrue(@Nullable Object o) {
return isNN(o) == true;
}

@EnsuresNonNullIf(expression = "#1", result = true)
static boolean returnsOrTrue(@Nullable Object o) {
// :: error: [contracts.conditional.postcondition]
return isNN(o) | true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import org.checkerframework.checker.nullness.qual.Nullable;

// An explicit call to booleanValue() keeps the facts that hold when its receiver is true or false.
public class ExplicitUnboxingKeepsConditionalRefinement {
@EnsuresNonNullIf(expression = "#1", result = true)
static Boolean isNN(@Nullable Object o) {
return o != null;
}

@EnsuresNonNullIf(expression = "#1", result = false)
static Boolean isNull(@Nullable Object o) {
return o == null;
}

void ifThen(@Nullable Object o) {
if (isNN(o).booleanValue()) {
o.hashCode();
}
}

void ifElse(@Nullable Object o) {
if (isNull(o).booleanValue()) {
// :: error: [dereference.of.nullable]
o.hashCode();
} else {
o.hashCode();
}
}

void not(@Nullable Object o) {
if (!isNull(o).booleanValue()) {
o.hashCode();
}
}

int ternary(@Nullable Object o) {
return isNN(o).booleanValue() ? o.hashCode() : 0;
}

boolean conditionalAnd(@Nullable Object o) {
return isNN(o).booleanValue() && o.hashCode() > 0;
}

int intValue(Integer i) {
return i.intValue() + i.intValue();
}
}
Loading
Loading