Skip to content

Commit

Permalink
Fix equality test; fixes #4806
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Kellogg <kelloggm@cs.washington.edu>
  • Loading branch information
mernst and kelloggm committed Jul 16, 2021
1 parent 59d47bb commit 07a1916
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions checker/tests/calledmethods/EnsuresCalledMethodsThisLub.java
@@ -0,0 +1,43 @@
import org.checkerframework.checker.calledmethods.qual.CalledMethods;
import org.checkerframework.checker.calledmethods.qual.EnsuresCalledMethods;

class EnsuresCalledMethodsThisLub {

@EnsuresCalledMethods(
value = "#1",
methods = {"toString", "equals"})
void call1(Object obj) {
obj.toString();
obj.equals(null);
}

@EnsuresCalledMethods(
value = "#1",
methods = {"toString", "hashCode"})
void call2(Object obj) {
obj.toString();
obj.hashCode();
}

void test(boolean b) {
if (b) {
call1(this);
} else {
call2(this);
}
@CalledMethods("toString") Object obj1 = this;
// :: error: (assignment)
@CalledMethods({"toString", "equals"}) Object obj2 = this;
}

void test_arg(Object arg, boolean b) {
if (b) {
call1(arg);
} else {
call2(arg);
}
@CalledMethods("toString") Object obj1 = arg;
// :: error: (assignment)
@CalledMethods({"toString", "equals"}) Object obj2 = arg;
}
}
Expand Up @@ -4,6 +4,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.BinaryOperator;
Expand Down Expand Up @@ -1181,6 +1182,9 @@ protected boolean supersetOf(CFAbstractStore<V, S> other) {
return false;
}
}
if (!Objects.equals(thisValue, other.thisValue)) {
return false;
}
for (Map.Entry<FieldAccess, V> e : other.fieldValues.entrySet()) {
FieldAccess key = e.getKey();
V value = fieldValues.get(key);
Expand Down

0 comments on commit 07a1916

Please sign in to comment.