False Negative: ContainsTypeMismatch.ql misses mismatched collection lookups once the receiver is routed through a raw alias.
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 58/100
Hướng nghiên cứu
Bắt đầu với checker Likely Bugs/Collections/ContainsTypeMismatch.ql và case PosCase5_Var5.java được mô tả trong issue. Theo dõi cách receiver Vector được khôi phục sau khi gán cho rawVec, sau đó thêm hoặc cập nhật một regression test để rawVec.lastIndexOf(arg) được báo cáo là không khớp giữa Byte và Float.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
False Negative: ContainsTypeMismatch.ql misses mismatched collection lookups once the receiver is routed through a raw alias.
Version
codeql 2.24.3
Checker
- Checker id:
Likely Bugs/Collections/ContainsTypeMismatch.ql - Checker description: This checker detects calls to Java collection methods where the argument type is incompatible with the collection's element type, such as calling
containswith an argument that can never match any element in the collection.
Description of the false negative
The collection still holds Byte values and the lookup still uses a Float. The only change is that the call goes through a raw alias before reaching lastIndexOf(...).
That should not be enough to hide the type mismatch from Likely Bugs/Collections/ContainsTypeMismatch.ql.
Affected test cases
PosCase5_Var5.java
rawVec.lastIndexOf(arg) is still searching a Vector<Byte> with a Float. The raw alias obscures generics, but it does not make the lookup compatible.
// Call lastIndexOf on a Vector<Byte> with an argument of type Float (first argument) should be flagged as incompatible type.
package scensct.var.pos;
import java.util.Vector;
public class PosCase5_Var5 {
public static void main(String[] args) {
Vector<? extends Byte> vec = new Vector<Byte>();
// Wildcard capture: still Vector<Byte> compatible
Float arg = 3.14f;
// Raw type manipulation to obscure but preserve generic info
Vector rawVec = vec;
// Checker must still detect Byte vs Float incompatibility
rawVec.lastIndexOf(arg);
}
}
Cause analysis
This looks like a generic-type recovery gap. Once the receiver is widened to a raw type, the query appears to stop using the element type information from the original collection.
That is too weak for this rule. Raw aliases are common in older Java code, and they do not change the fact that a Float can never match an element from a Vector<Byte>.
References
None known.
- Ngôn ngữ chính
- CodeQL
- Star
- 10.1k
- Fork
- 2.1k
- Merge trung bình
- 2 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 134
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của github/codeql
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
false-positive
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
false-positive
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Tất cả issue của github/codeql
Issue tương tự
-
ZCode 3.14.3 に対応する Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
supermomonga/zcode-acp#24 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
learningequality/ricecooker#747 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
KhronosGroup/glTF-Blender-IO#2769 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100