False Negative: ContradictoryTypeChecks.ql misses impossible subtype checks once the false branch is expressed through aliases or lambdas.
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Đọc Likely Bugs/Likely Typos/ContradictoryTypeChecks.ql cùng với PosCase1_Var3.java và PosCase2_Var1.java. Theo dõi cách checker xử lý các nhánh false, lambda và alias; hoàn tất khi cả hai phép toán subtype bất khả thi đều được báo cáo là các kiểm tra kiểu mâu thuẫn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
False Negative: ContradictoryTypeChecks.ql misses impossible subtype checks once the false branch is expressed through aliases or lambdas.
Version
codeql 2.24.3
Checker
- Checker id:
Likely Bugs/Likely Typos/ContradictoryTypeChecks.ql - Checker description: This checker detects contradictory type checks where a variable is first checked to be of a supertype via an instanceof guard, and later accessed with a cast or instanceof check for a subtype, which is impossible.
Description of the false negative
Both samples keep the same contradiction: after ruling out a supertype, the code still checks or casts the same value as if it were a subtype of that supertype. One variant hides the contradiction in a lambda branch, and the other splits it across an alias.
That is still exactly the bug Likely Bugs/Likely Typos/ContradictoryTypeChecks.ql is supposed to catch.
Affected test cases
PosCase1_Var3.java
The lambda packaging is incidental. On the false side of obj instanceof CharSequence, the code still performs String s = (String) obj, which remains contradictory.
// A variable is checked with instanceof for a supertype in a guard condition, and on the guard's false path, the same variable is cast to a subtype of that supertype should be flagged as contradictory type check.
package scensct.var.pos;
public class PosCase1_Var3 {
public static void main(String[] args) {
Object obj = new Object();
// Use a ternary operator to choose a path, but keep the cast in the false branch
Runnable action = (obj instanceof CharSequence)
? () -> { CharSequence cs = (CharSequence) obj; }
: () -> { String s = (String) obj; }; // Contradictory cast inside lambda
action.run();
}
}
PosCase2_Var1.java
Using temp in the guard and obj in the false branch does not change the underlying contradiction. Both names refer to the same object.
// A variable is checked with instanceof for a supertype in a guard condition, and on the guard's false path, the same variable is checked with instanceof for a subtype of that supertype should be flagged as contradictory type check.
package scensct.var.pos;
public class PosCase2_Var1 {
public static void main(String[] args) {
Object obj = new Object();
// Introduce a temporary variable to alias the original
Object temp = obj;
// Guard condition on the alias
if (temp instanceof CharSequence) {
CharSequence cs = (CharSequence) temp;
} else {
// The false branch still refers to the original variable
if (obj instanceof String) {
String s = (String) obj;
}
}
}
}
Cause analysis
The query seems too syntax-driven around a single if/else shape. Once the contradictory check is split across aliases or packed into another control-flow construct, the relationship between the guard and the impossible subtype operation is lost.
That makes the rule easier to bypass than it should be. The contradiction is semantic, not stylistic.
References
None known.
- Ngôn ngữ chính
- CodeQL
- Star
- 10.1k
- Fork
- 2.1k
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 143
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
-
agentic-workflows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
false-positive javascript
Độ 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
Tất cả issue của github/codeql
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
palladius/rails8-app-on-gcp#145 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
elastic/gradle-plugins#156 ·
-
area:workflow bug ready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
fil-donadoni/tolaria#4409 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotenvx/dotenv-vscode#139 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Fission-AI/OpenSpec#1960 ·