False Negative: ContradictoryTypeChecks.ql misses impossible subtype checks once the false branch is expressed through aliases or lambdas.
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
調査の方向性
Likely Bugs/Likely Typos/ContradictoryTypeChecks.ql を PosCase1_Var3.java および PosCase2_Var1.java と併せて読みます。checker が false ブランチ、ラムダ、エイリアスをどのように処理するかを追跡します。両方の不可能なサブタイプ操作が矛盾した型チェックとして報告されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- CodeQL
- スター
- 10.1k
- フォーク
- 2.1k
- 平均マージ
- 2日 16時間
- マージ済み PR(30日)
- 143
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/codeql のほかの issue
-
agentic-workflows
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
false-positive javascript
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
false-positive
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
ZCode 3.14.3 に対応する オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
supermomonga/zcode-acp#24 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
learningequality/ricecooker#747 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
KhronosGroup/glTF-Blender-IO#2769 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100