github / github/codeql

Java: `hasSubtype` / `getASubtype` does not work correctly for generic types

Đang mở
#8,339 2 bình luận 0 reaction 1 người được giao Được @aschackmull nhận Xem trên GitHub
question
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

Based on https://github.com/github/codeql/pull/8241#discussion_r815508557

The predicate `hasSubtype(RefType, Type)` and predicates which are based on it, such as `RefType.getASubtype()` do not work correctly for generic types. For example for the generic type `java.util.List`, the type `java.util.ArrayList` is not found ([example query](https://lgtm.com/query/5617555852827933522/)).

The underlying issue is most likely related to how CodeQL in general handles type hierarchies of generic, parameterized and raw types, and which is likely the reason why `getASourceSupertype()` exists. Generic types simply seem to have no subtypes ([example query](https://lgtm.com/query/4703394327948888047/)), which therefore affects all predicates based on `hasSubtype`; this is closely related to #5521.

I am not sure what the Java Language Specification says about this, or whether it says anything about this situation at all. Because generic types do not appear in type usage (as far as I know); type usage either references parameterized or raw types.
The current issue with the CodeQL predicates is that there are a lot predicates for navigating the hierarchy (`hasSubtype`, `getASubtype`, `getASupertype`, ...), but all of them do not work correctly for generic types. This will likely be confusing (and maybe even frustrating) for new users.

If possible, without violating any constraints and without negatively affecting performance too much, would it be possible to consider generic types in the type hierarchy related predicates by default (possibly rendering `getASourceSupertype` redundant)?

---

Also, to avoid any misunderstanding, here is how CodeQL currently represents the types (with their name):
- Generic type: `List`; represents the class or interface declared in the source file, or in a third party class file
- Raw type: `List<>`; represents usage of a raw type, e.g. `List strings = ...`
- Parameterized type: `List`

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.