ClassHierarchy.isASubtypeOf sometimes returns Unknown even though the supertype is final

Issue #182 resolved
Andreas Bauer created an issue

I encountered a problem with the subtype checker in ClassHierarchy.

Assume we have a project with some final class C {}, and the JDK is not part of the project. Then, classHierarchy.isASubtypeOf(ObjectType("java/util/ArrayList"), ObjectType("myproject/C")) == No. This is as expected. Even though ArrayList is an unknown type, we know that it can not be a subtype of C since C is final.

However, if we add a class MyList extends ArrayList {} to the project, the same check now returns Unknown.

It seems like this is because ArrayList is now “known” to the ClassHierarchy (because it appears in the MyList class definition?), and whether or not the supertype is final is only checked when the subtype is unknown. This looks wrong to me.

(Link to the code in question.)

Comments (4)

  1. Michael Eichberg repo owner

    It is definitively an unwanted imprecision which I will fix. Thanks for the very helpful description!

  2. Log in to comment