Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
6c2805b
splitAssignments omits sides whose value an assignment might change
mernst Oct 30, 2026
7da53d8
Merge branch 'master' into split-assignments-sound
mernst Oct 30, 2026
cc3d25e
splitAssignments: account for nested assignments; ignore writes to a …
mernst Oct 30, 2026
847ddeb
splitAssignments: reuse store aliasing, restore fast path, fix Javado…
mernst Oct 30, 2026
a90af0c
splitAssignments: find all assignments in the tree, sound array alias…
mernst Oct 30, 2026
6d0da35
Test assignment in comparison with generic receivers that are not sub…
mernst Oct 30, 2026
0c1dc85
Merge remote-tracking branch 'upstream/master' into split-assignments…
mernst Oct 31, 2026
e535d62
Suppress unchecked-cast warning in AssignmentInComparison test
mernst Nov 1, 2026
9044449
Handle parenthesized and unrecognized assignment targets in splitAssi…
mernst Nov 3, 2026
decfa94
Merge branch 'master' into split-assignments-sound
mernst Nov 3, 2026
edcd637
Merge branch 'master' into split-assignments-sound
mernst Nov 7, 2026
ec91366
splitAssignments: scan anonymous class initializers; add tests
mernst Nov 8, 2026
cb80e70
Don't refine a left operand that the right operand might reassign
mernst Nov 8, 2026
c4ea38d
Move the treatment of a right operand that reassigns the left operand…
mernst Nov 8, 2026
0331413
Merge branch 'master' into split-assignments-sound
mernst Nov 10, 2026
dd4e211
AssignmentTargetScanner does not descend into annotations
mernst Nov 12, 2026
bc5f209
Strengthen the regression tests for annotation arguments
mernst Nov 12, 2026
9970220
splitAssignments: account for evaluation order, method calls, and the…
mernst Nov 12, 2026
1b027a1
Suppress Interning Checker warning about reference equality of AST nodes
mernst Nov 12, 2026
db88680
splitAssignments: account for all later writes in the comparison; fix…
mernst Nov 12, 2026
34b5d4e
Fix CI: document refineGT and refineGTE; handle nullable values in Lo…
mernst Nov 12, 2026
d6614eb
Merge branch 'master' into split-assignments-sound
mernst Nov 13, 2026
d6f3bc3
Rename splitAssignments to nodesWithValueOf; clarify documentation
mernst Nov 13, 2026
675642e
Rename Writes to WrittenLocations
mernst Nov 13, 2026
56f8009
canAlias compares erased types and every bound; move canAlias and isS…
mernst Nov 13, 2026
666211a
JavaExpression.fromTree looks through parentheses
mernst Nov 13, 2026
0945ba9
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 13, 2026
9c20c72
Merge branch 'fromtree-parentheses' into split-assignments-sound
mernst Nov 13, 2026
7e9ab4f
Move the Index Checker's use of nodesWithValueOf to a separate pull r…
mernst Nov 13, 2026
e47dcbc
Parenthesize operands in BinaryOperation and UnaryOperation toString;…
mernst Nov 13, 2026
cf8c093
Leave isSideEffectFree in the store; document canAlias's non-conserva…
mernst Nov 13, 2026
75f6d6c
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 13, 2026
b228a65
Use the factory's isSideEffectFree, which CFAbstractAnalysis no longe…
mernst Nov 13, 2026
3add1ec
Match writes to a static field regardless of receiver; document canAl…
mernst Nov 13, 2026
9162e0e
Test canAlias on arrays of type variables bounded by Object
mernst Nov 13, 2026
79d6949
Move canAlias logic to TypesUtils; handle union types and wildcards; …
mernst Nov 14, 2026
71cabbb
Merge remote-tracking branch 'origin/can-alias-erased-bounds' into sp…
mernst Nov 14, 2026
c3c07b8
Document that canAlias is not conservative for arrays of unrelated types
mernst Nov 14, 2026
a383b4a
Merge remote-tracking branch 'origin/can-alias-erased-bounds' into sp…
mernst Nov 14, 2026
f0801fd
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 15, 2026
e2fe758
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 15, 2026
5c88eeb
Merge branch 'master' into fromtree-parentheses
mernst Nov 15, 2026
406ba7b
Merge branch 'fromtree-parentheses' into split-assignments-sound
mernst Nov 15, 2026
f80904b
Parenthesize an operation receiver in MethodCall.toString; nodesWithV…
mernst Nov 15, 2026
c677a19
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 15, 2026
d7b6c01
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 15, 2026
ab63bdc
Merge branch 'master' into fromtree-parentheses
mernst Nov 15, 2026
20f1f10
Merge branch 'fromtree-parentheses' into split-assignments-sound
mernst Nov 15, 2026
bf4aa9b
canAlias compares the bounds of a wildcard's type parameter; CFAbstra…
mernst Nov 16, 2026
8944dd6
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 16, 2026
bb03ffd
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 16, 2026
6ba3cb1
Merge branch 'master' into fromtree-parentheses
mernst Nov 16, 2026
c25eb23
Merge branch 'fromtree-parentheses' into split-assignments-sound
mernst Nov 16, 2026
ade4c68
Describe canAlias's comparison of erased types in the changelog
mernst Nov 17, 2026
4c39024
Merge remote-tracking branch 'origin/can-alias-erased-bounds' into sp…
mernst Nov 17, 2026
1364547
Merge remote-tracking branch 'upstream/master' into split-assignments…
mernst Nov 17, 2026
6dd0f64
A write before an assignment's store does not change the target's sto…
mernst Nov 17, 2026
0cca2cc
Test comparisons whose later operand changes the earlier one
mernst Nov 17, 2026
fe5ca1a
MethodCall.toString parenthesizes a receiver that is a unary or binar…
mernst Nov 17, 2026
e5e3ae5
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst Nov 17, 2026
ac967f5
Test the target-value guard with a local variable target
mernst Nov 17, 2026
b1d6661
Merge github.com:typetools/checker-framework into can-alias-erased-bo…
mernst Nov 18, 2026
77a50ce
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 18, 2026
d89bcd2
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst Nov 18, 2026
b6a284b
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst Nov 18, 2026
e51b950
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 18, 2026
455ce3d
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 18, 2026
073bec0
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst Nov 18, 2026
6d1557c
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst Nov 18, 2026
c0cf6b7
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 19, 2026
b865d1a
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 19, 2026
25687d1
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst Nov 19, 2026
c97be8e
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst Nov 19, 2026
c0cb6b3
Clarify canAlias documentation and changelog entry; test a union type…
mernst Nov 21, 2026
651a7f0
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 21, 2026
06a3972
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 21, 2026
05891e8
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 21, 2026
d021131
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst Nov 21, 2026
a0cc72b
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst Nov 21, 2026
dd2a276
Parenthesize every postfix operand that a postfix operation could reg…
mernst Nov 21, 2026
3696c7d
Print a static field access as Foo.f, not Foo.class.f
mernst Nov 21, 2026
0785feb
Do not change dataflow/build.gradle in this pull request
mernst Nov 21, 2026
cd93fac
Discard refinements that a comparison invalidates
mernst Nov 22, 2026
d37faa7
Do not change how a static field access prints in this pull request
mernst Nov 22, 2026
608ca1a
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst Nov 22, 2026
7b4921f
Move comparison-specific Index refinements to later pull requests; ac…
mernst Nov 22, 2026
d356f6a
Do not propagate a qualifier that a later call might invalidate; acco…
mernst Nov 23, 2026
bee5a86
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 23, 2026
9dead35
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 23, 2026
934b638
Merge branch 'master' into methodcall-toString-parenthesize-receiver
mernst Nov 23, 2026
2fc8be1
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst Nov 23, 2026
bad0810
Do not parenthesize an IteratedCollectionElement receiver; fix test J…
mernst Nov 23, 2026
cde73f7
Give one reason for parenthesizing a postfix operand: regrouping or f…
mernst Nov 24, 2026
51a463a
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 24, 2026
86f85e3
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 24, 2026
c02d222
Merge github.com:typetools/checker-framework into methodcall-toString…
mernst Nov 24, 2026
48a5688
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 25, 2026
77a2623
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 25, 2026
1001434
Merge branch 'methodcall-toString-parenthesize-receiver' into split-a…
mernst Nov 25, 2026
a668b08
Address review: stale sequence bounds, string conversion, array-refer…
mernst Nov 25, 2026
7271c62
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 26, 2026
32731db
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 26, 2026
350791f
Reformat
mernst Nov 26, 2026
97e88f9
Merge remote-tracking branch 'upstream/master' into can-alias-erased-…
mernst Nov 26, 2026
62f8fb5
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 26, 2026
d70d366
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 27, 2026
74d27a9
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 27, 2026
919fbc1
Index tests: give the test helpers lower bounds; reassign a += receiv…
mernst Nov 27, 2026
1250c62
Move the eqChanged test to the pull request that makes it pass
mernst Nov 27, 2026
61d8d2d
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 27, 2026
73983a1
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 27, 2026
cbbe62d
Address review: bracketed offsets, writes in a subtracted offset, pos…
mernst Nov 28, 2026
b71d005
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 28, 2026
ec83693
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 28, 2026
ca4f0d2
Reformat
mernst Nov 28, 2026
5d4c000
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 28, 2026
1bb6c86
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 28, 2026
dc1566b
Make splitAssignments structural and final; check writes in a candida…
mernst Nov 29, 2026
e27e322
nodesWithValueOf does not count the writes of a candidate's own call
mernst Nov 29, 2026
92eafec
A write to an array element at a different constant index does not ch…
mernst Nov 29, 2026
c89ae52
Less Than Checker: a floating-point comparison does not imply an inte…
mernst Nov 29, 2026
aaaafca
Merge branch 'index-floating-point-integral-bound' into split-assignm…
mernst Nov 29, 2026
3963ac4
Document that a write at one constant index does not change another e…
mernst Nov 29, 2026
d0fcfb8
Keep the refinement of a strict floating-point comparison; fix commen…
mernst Nov 29, 2026
9f9d636
Merge branch 'index-floating-point-integral-bound' into split-assignm…
mernst Nov 29, 2026
aa998c6
Count the calls of an enhanced for loop and a try-with-resources stat…
mernst Nov 29, 2026
e6ab026
Merge branch 'master' into can-alias-erased-bounds
mernst Nov 30, 2026
5acb5dc
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Nov 30, 2026
8b1aa28
nodesWithValueOf: a node with no source tree is not changed by a wri…
mernst Nov 30, 2026
6c9be16
Make the aliased-receiver tests detect a missed .other diagnostic; ch…
mernst Dec 1, 2026
36f22b8
Merge branch 'master' into can-alias-erased-bounds
mernst Dec 1, 2026
6122ce5
Merge branch 'can-alias-erased-bounds' into split-assignments-sound
mernst Dec 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,15 @@ private void notEqualToValue(

if (intLiteral == 0) {
if (atypeFactory.areSameByClass(otherAnno, NonNegative.class)) {
List<Node> internals = splitAssignments(otherNode);
List<Node> internals = nodesWithValueOf(otherNode);
for (Node internal : internals) {
JavaExpression je = JavaExpression.fromNode(internal);
store.insertValue(je, POS);
}
}
} else if (intLiteral == -1) {
if (atypeFactory.areSameByClass(otherAnno, GTENegativeOne.class)) {
List<Node> internals = splitAssignments(otherNode);
List<Node> internals = nodesWithValueOf(otherNode);
for (Node internal : internals) {
JavaExpression je = JavaExpression.fromNode(internal);
store.insertValue(je, NN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ private boolean isArrayLengthAccess(Node node) {
private void refineEq(Node left, Node right, CFStore store) {
List<JavaExpression> exprs = new ArrayList<>(2);
List<AnnotationMirror> annos = new ArrayList<>(2);
for (Node internal : splitAssignments(left)) {
for (Node internal : nodesWithValueOf(left)) {
exprs.add(JavaExpression.fromNode(internal));
annos.add(getAnno(internal));
}
for (Node internal : splitAssignments(right)) {
for (Node internal : nodesWithValueOf(right)) {
exprs.add(JavaExpression.fromNode(internal));
annos.add(getAnno(internal));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,13 @@ private void refineEq(
UBQualifier glb = rightQualifier.glb(leftQualifier);
Comment thread
mernst marked this conversation as resolved.
Resolved
AnnotationMirror glbAnno = atypeFactory.convertUBQualifierToAnnotation(glb);

List<Node> internalsRight = splitAssignments(right);
List<Node> internalsRight = nodesWithValueOf(right);
for (Node internal : internalsRight) {
JavaExpression rightJe = JavaExpression.fromNode(internal);
store.insertValue(rightJe, glbAnno);
}

List<Node> internalsLeft = splitAssignments(left);
List<Node> internalsLeft = nodesWithValueOf(left);
for (Node internal : internalsLeft) {
JavaExpression leftJe = JavaExpression.fromNode(internal);
store.insertValue(leftJe, glbAnno);
Expand Down Expand Up @@ -495,7 +495,7 @@ private void refineNeqSequenceLength(
UBQualifier newQualifier =
UBQualifier.createUBQualifier(sequence, Integer.toString(lengthOffset));
otherQualifier = otherQualifier.glb(newQualifier);
for (Node internal : splitAssignments(otherNode)) {
for (Node internal : nodesWithValueOf(otherNode)) {
Comment thread
mernst marked this conversation as resolved.
Resolved
JavaExpression leftJe = JavaExpression.fromNode(internal);
store.insertValue(leftJe, atypeFactory.convertUBQualifierToAnnotation(otherQualifier));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected TransferResult<NullnessValue, NullnessStore> strengthenAnnotationOfEqu
NullnessStore thenStore = res.getThenStore();
NullnessStore elseStore = res.getElseStore();

List<Node> secondParts = splitAssignments(secondNode);
List<Node> secondParts = nodesWithValueOf(secondNode);
for (Node secondPart : secondParts) {
JavaExpression secondInternal = JavaExpression.fromNode(secondPart);
if (CFAbstractStore.canInsertJavaExpression(secondInternal)) {
Expand Down
106 changes: 106 additions & 0 deletions checker/tests/index/SameLenComparisonChangesOperand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// An operand of a length comparison must not be related to the other operand if the comparison
// changes the operand's value after evaluating it. For example, if i is 12, then after the
// comparison in changedLater, s is "ab3" but "x" + i is "x3".

public class SameLenComparisonChangesOperand {

void changedLater(int i, String s) {
if (("x" + i).length() == (s = "ab" + (i = 3)).length()) {
String u = "x" + i;
for (int k = 0; k < s.length(); k++) {
// :: error: (argument)
u.charAt(k);
}
}
}

void unchanged(int i, String s) {
if (("x" + i).length() == s.length()) {
String u = "x" + i;
for (int k = 0; k < s.length(); k++) {
u.charAt(k);
}
}
}

// After the assignment, s + "x" is one character longer than t.
void changedInAssignment(String s, String t) {
if ((s = s + "x").length() == t.length()) {
String u = s + "x";
for (int k = 0; k < u.length(); k++) {
// :: error: (argument)
t.charAt(k);
}
}
}

void unchangedInAssignment(String s, String t, String v) {
if ((s = v + "x").length() == t.length()) {
String u = v + "x";
for (int k = 0; k < u.length(); k++) {
t.charAt(k);
}
}
}

static class Holder {
String text = "";
}

static Holder current = new Holder();

// Not side-effect-free.
static String swap() {
current = new Holder();
return "";
}

// The `+=` evaluates `current` before it evaluates `swap()`, which reassigns `current`. So the
// assignment stores into the `text` field of the old `current`. (A string conversion cannot
// reassign `current` this way: the analysis assumes that every `toString()` method is
// side-effect-free, like `Object.toString()`.)
void compoundAssignmentReassignsReceiver(String peer) {
if ((current.text += swap()).length() == peer.length()) {
for (int k = 0; k < peer.length(); k++) {
// :: error: (argument)
current.text.charAt(k);
}
}
}

static class Box {
String text = "";

@Override
public String toString() {
return text;
}
}

// Not side-effect-free.
static String setText(Box box, String t) {
box.text = t;
return t;
}

// The string conversion of `box` calls `box.toString()`, whose result the call to `setText`
// changes. So after the comparison, "p" + box might be longer than s.
void changedByToString(Box box, String s) {
if (("p" + box).length() == (s = setText(box, "abc")).length()) {
String u = "p" + box;
for (int k = 0; k < u.length(); k++) {
// :: error: (argument)
s.charAt(k);
}
}
}

void unchangedByToString(Box box, String s, String t) {
if (("p" + box).length() == (s = t).length()) {
String u = "p" + box;
for (int k = 0; k < u.length(); k++) {
s.charAt(k);
}
}
}
}
60 changes: 60 additions & 0 deletions checker/tests/nonempty/AssignmentInComparison.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.util.ArrayList;
import java.util.List;
import org.checkerframework.checker.nonempty.qual.NonEmpty;

// The Non-Empty Checker unrefines aliases at a side effect. A call in the right-hand side of an
// assignment does not change the value that the assignment stores, so comparing the assignment
// refines its target.
class AssignmentInComparison {

// Not side-effect-free.
List<String> newList() {
return new ArrayList<>();
}

void callInRhs(@NonEmpty List<String> ne) {
List<String> l;
if ((l = newList()) == ne) {
@NonEmpty List<String> m = l;
}
}

// The call in the rhs might change the abstract value of the list that `slots` denotes, but not
// which array `slots` denotes, so it does not change which element the assignment stores into.
void callInRhsArrayElementTarget(List<String>[] slots, @NonEmpty List<String> ne) {
if ((slots[0] = newList()) == ne) {
@NonEmpty List<String> m = slots[0];
}
}

// Not side-effect-free.
static List<String> clearAndReturn(List<String> l) {
l.clear();
return l;
}

// The call in the right operand might empty the list that `a` denotes, after the left operand
// reads `a`. The qualifier that `a` had when it was read does not hold for `b`.
void callInRightOperandChangesLeftOperand(List<String> a) {
if (a.isEmpty()) {
return;
}
List<String> b;
if (a == (b = clearAndReturn(a))) {
// :: error: [assignment]
@NonEmpty List<String> m = b;
}
}

// A reassignment of `a` in the right operand does not change the list that `a` denoted when the
// left operand read it.
void reassignmentInRightOperand(List<String> a, List<String> c) {
if (a.isEmpty()) {
return;
}
List<String> b;
if (a == (b = (a = c))) {
@NonEmpty List<String> m = b;
}
}
}
32 changes: 32 additions & 0 deletions checker/tests/nullness/ArrayAliasingIntersectionBound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import org.checkerframework.checker.nullness.qual.Nullable;

// Arrays whose element types are a type variable and one of its bounds can be the same array.
public class ArrayAliasingIntersectionBound {

static <T extends Number & Comparable<T>> void writeThroughTypeVariable(
@Nullable T[] ts, @Nullable Comparable<T>[] cs, T t) {
if (cs[0] != null) {
ts[0] = null;
// If `ts` and `cs` are the same array, the assignment to `ts[0]` sets `cs[0]` to null.
// :: error: [dereference.of.nullable]
cs[0].compareTo(t);
}
}

static <T extends Number & Comparable<T>> void writeThroughBound(
@Nullable T[] ts, @Nullable Comparable<T>[] cs, T t) {
if (ts[0] != null) {
cs[0] = null;
// If `ts` and `cs` are the same array, the assignment to `cs[0]` sets `ts[0]` to null.
// :: error: [dereference.of.nullable]
ts[0].intValue();
}
}

static void unrelatedArrays(@Nullable Integer[] is, @Nullable String[] ss) {
if (is[0] != null) {
ss[0] = null;
is[0].intValue();
}
}
}
17 changes: 17 additions & 0 deletions checker/tests/nullness/ArrayAliasingParameterizations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;

// Arrays whose element types are two parameterizations of a generic type can be the same array,
// even if neither parameterization is a subtype of the other.
public class ArrayAliasingParameterizations {

static void elementOfWildcardLists(
@Nullable List<? extends Number>[] xs, @Nullable List<? super Integer>[] ys) {
if (xs[0] != null) {
ys[0] = null;
// If `xs` and `ys` are the same array, the assignment to `ys[0]` sets `xs[0]` to null.
// :: error: [dereference.of.nullable]
xs[0].size();
}
}
}
24 changes: 24 additions & 0 deletions checker/tests/nullness/ArrayAliasingTypeVariables.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import org.checkerframework.checker.nullness.qual.Nullable;

// An array whose element type is a type variable bounded by Object can be the same array as an
// array of any reference type, because a caller can instantiate the type variable to that type.
public class ArrayAliasingTypeVariables {

static <T> void typeVariableAndClass(@Nullable T[] ts, @Nullable String[] ss) {
if (ss[0] != null) {
ts[0] = null;
// If `ts` and `ss` are the same array, the assignment to `ts[0]` sets `ss[0]` to null.
// :: error: [dereference.of.nullable]
ss[0].length();
}
}

static <T, S> void twoTypeVariables(@Nullable T[] ts, @Nullable S[] ss) {
if (ss[0] != null) {
ts[0] = null;
// If `ts` and `ss` are the same array, the assignment to `ts[0]` sets `ss[0]` to null.
// :: error: [dereference.of.nullable]
ss[0].toString();
}
}
}
Loading
Loading