mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Java: Don't inherit methods from co-/contra-variant supertypes.
This commit is contained in:
@@ -435,22 +435,6 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
hasInterfaceMethod(m, declaringType) and hidden = false
|
||||
}
|
||||
|
||||
private predicate noMethodExtraction() {
|
||||
not methods(_, _, _, _, this, _) and
|
||||
exists(Method m | methods(m, _, _, _, getSourceDeclaration(), _) and m.isInheritable())
|
||||
}
|
||||
|
||||
private predicate canInheritFromSupertype(RefType sup) {
|
||||
sup = getASupertype() and
|
||||
(noMethodExtraction() implies supertypeSrcDecl(sup, getSourceDeclaration()))
|
||||
}
|
||||
|
||||
pragma[nomagic]
|
||||
private predicate supertypeSrcDecl(RefType sup, RefType srcDecl) {
|
||||
sup = getASupertype() and
|
||||
srcDecl = sup.getSourceDeclaration()
|
||||
}
|
||||
|
||||
private predicate hasNonInterfaceMethod(Method m, RefType declaringType, boolean hidden) {
|
||||
m = getAMethod() and
|
||||
this = declaringType and
|
||||
@@ -464,7 +448,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
else h1 = false
|
||||
) and
|
||||
(not sup instanceof Interface or this instanceof Interface) and
|
||||
canInheritFromSupertype(sup) and
|
||||
this.extendsOrImplements(sup) and
|
||||
sup.hasNonInterfaceMethod(m, declaringType, h2) and
|
||||
hidden = h1.booleanOr(h2) and
|
||||
exists(string signature |
|
||||
@@ -491,7 +475,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
exists(RefType sup |
|
||||
sup.interfaceMethodCandidateWithSignature(m, signature, declaringType) and
|
||||
not cannotInheritInterfaceMethod(signature) and
|
||||
canInheritFromSupertype(sup) and
|
||||
this.extendsOrImplements(sup) and
|
||||
m.isInheritable()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
| NamingTest.java:4:17:4:22 | equals | Method NamingTest.equals(..) could be confused with overloaded method $@, since dispatch depends on static types. | NamingTest.java:3:17:3:22 | equals | equals |
|
||||
| NamingTest.java:7:17:7:22 | equals | Method NamingTest.equals(..) could be confused with overloaded method $@, since dispatch depends on static types. | NamingTest.java:6:17:6:22 | equals | equals |
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class NamingTest {
|
||||
public boolean equals(Object other) { return false; }
|
||||
public boolean equals(NamingTest other) { return true; }
|
||||
|
||||
|
||||
public void visit(Object node) {}
|
||||
public void visit(NamingTest t) {}
|
||||
|
||||
public class Elem<T> {}
|
||||
|
||||
public Object get(List<Elem<String>> lll) {
|
||||
Predicate<?> p = null;
|
||||
p.test(null);
|
||||
return lll.stream().map(l -> l).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user