Skip to content

Commit a7b677b

Browse files
committed
Java: Bugfix for SuperAccess.isOwnInstanceAccess().
1 parent 110a4c8 commit a7b677b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,13 +1670,25 @@ abstract class InstanceAccess extends Expr {
16701670
/** Holds if this instance access is to an enclosing instance of type `t`. */
16711671
predicate isEnclosingInstanceAccess(RefType t) {
16721672
t = this.getQualifier().getType().(RefType).getSourceDeclaration() and
1673-
t != this.getEnclosingCallable().getDeclaringType()
1673+
t != this.getEnclosingCallable().getDeclaringType() and
1674+
not this.isSuperInterfaceAccess()
16741675
or
1675-
not exists(this.getQualifier()) and
1676+
(not exists(this.getQualifier()) or this.isSuperInterfaceAccess()) and
16761677
exists(LambdaExpr lam | lam.asMethod() = this.getEnclosingCallable() |
16771678
t = lam.getAnonymousClass().getEnclosingType()
16781679
)
16791680
}
1681+
1682+
// A default method on an interface, `I`, may be invoked using `I.super.m()`.
1683+
// This always refers to the implemented interfaces of `this`. This form of
1684+
// qualified `super` cannot be combined with accessing an enclosing instance.
1685+
// JLS 15.11.2. "Accessing Superclass Members using super"
1686+
// JLS 15.12. "Method Invocation Expressions"
1687+
// JLS 15.12.1. "Compile-Time Step 1: Determine Type to Search"
1688+
private predicate isSuperInterfaceAccess() {
1689+
this instanceof SuperAccess and
1690+
this.getQualifier().getType().(RefType).getSourceDeclaration() instanceof Interface
1691+
}
16801692
}
16811693

16821694
/**

0 commit comments

Comments
 (0)