False Negative: ContainsTypeMismatch.ql misses mismatched collection lookups once the receiver is routed through a raw alias.
還沒有人認領這個 Issue。
評估
研究方向
從 Likely Bugs/Collections/ContainsTypeMismatch.ql checker 和 issue 中描述的 PosCase5_Var5.java case 開始。追蹤 Vector receiver 在指派給 rawVec 後是如何復原的,然後新增或更新回歸測試,使 rawVec.lastIndexOf(arg) 被報告為 Byte 與 Float 不相符。
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- CodeQL
- 星號
- 10.1k
- 分支
- 2.1k
- 平均合併
- 2 天 16 小時
- 30 天內合併 PR
- 143
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/codeql 的其他 Issue
-
agentic-workflows
難度 2/5 1-3 小時 新手友好度 70/100
-
false-positive javascript
難度 2/5 1-3 小時 新手友好度 84/100
-
難度 2/5 1-3 小時 新手友好度 82/100
-
難度 2/5 1-3 小時 新手友好度 78/100
-
false-positive
難度 2/5 1-3 小時 新手友好度 70/100
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 70/100
pastelsky/bundlephobia#1122 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
anthropics/skills#1811 · 1 則留言 ·
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
CachyOS/distribution#587 ·
-
bug
難度 2/5 1-3 小時 新手友好度 75/100
datalayer/mcp-compose#42 ·
-
難度 2/5 1-3 小時 新手友好度 70/100