Skip to content

Commit

Permalink
ReportChecker: Fix array access crash
Browse files Browse the repository at this point in the history
  • Loading branch information
smillst committed Dec 13, 2023
1 parent 3eb26a9 commit 4b5e2c9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import javax.lang.model.element.Modifier;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory;
import org.checkerframework.common.basetype.BaseTypeChecker;
Expand Down Expand Up @@ -213,7 +212,7 @@ public Void visitIdentifier(IdentifierTree tree, Void p) {

@Override
public Void visitAssignment(AssignmentTree tree, Void p) {
VariableElement member = (VariableElement) TreeUtils.elementFromUse(tree.getVariable());
Element member = TreeUtils.elementFromUse(tree.getVariable());
boolean report = this.atypeFactory.getDeclAnnotation(member, ReportWrite.class) != null;

if (report) {
Expand Down
6 changes: 6 additions & 0 deletions framework/tests/report/Accesses.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ void accessesMethod(Demo d) {
// :: error: (methodcall)
d.equals(d.foo(null));
}

Object[] array = new Object[] {1, 2, 3};

void accessArray() {
array[0] = 1;
}
}

0 comments on commit 4b5e2c9

Please sign in to comment.