Skip to content

Commit a0636ff

Browse files
authored
Merge pull request #9545 from igfoo/igfoo/type_cycles
Java: Fix RefType.getAStrictAncestor() in the presence of type hierarchy cycles
2 parents d0bf424 + b524fb4 commit a0636ff

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,12 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
413413
/** Gets a direct or indirect supertype of this type, including itself. */
414414
RefType getAnAncestor() { hasDescendant(result, this) }
415415

416-
/** Gets a direct or indirect supertype of this type, not including itself. */
417-
RefType getAStrictAncestor() { result = this.getAnAncestor() and result != this }
416+
/**
417+
* Gets a direct or indirect supertype of this type.
418+
* This does not including itself, unless this type is part of a cycle
419+
* in the type hierarchy.
420+
*/
421+
RefType getAStrictAncestor() { result = this.getASupertype().getAnAncestor() }
418422

419423
/**
420424
* Gets the source declaration of a direct supertype of this type, excluding itself.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public class Test {
2+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| BiFunction<? super Object,? super Object,? extends Object> |
2+
| BiFunction<? super Object,? super Object,?> |
3+
| Function<? super Object,? extends Object> |
4+
| Function<? super Object,?> |
5+
| Map<? extends Object,? extends Object> |
6+
| Map<?,?> |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java
2+
3+
from RefType t
4+
where t = t.getAStrictAncestor()
5+
select t.toString()

0 commit comments

Comments
 (0)