False positive: java/field-masks-super-field triggered on Kotlin sealed class with open val constructor parameters
まだ誰も着手していません。
評価
調査の方向性
Kotlin の再現例と java/field-masks-super-field クエリから始め、次に Kotlin Live Literals に関する PR #10859 とその処理を比較します。sealed class、object subclasses、open val parameters が Java extractor によってどのように表現されるかを確認してください。このパターンでは alert が抑制され、真正な field shadowing は引き続き報告されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
The rule java/field-masks-super-field is producing a false positive on a Kotlin sealed class that uses open val constructor parameters. No actual field shadowing exists in the source code.
CodeQL Version
GitHub Advanced Security (cloud) - latest on github.dev
Language
Kotlin (analysed via Java extractor)
Minimal Reproduction
sealed class ImageType(open val width: Int, open val height: Int) {
object Portrait : ImageType(78, 98)
object Square : ImageType(78, 78)
object PortraitLarge : ImageType(163, 205)
}
What CodeQL Reports
"This field shadows another field called
width/heightin a superclass."
Rule ID: java/field-masks-super-field
Why This Is a False Positive
- No subclass redeclares
widthorheightin its body - Every
objectsubclass simply passes values via the constructor to the parent - There is no Java-style field shadowing at the source level
- The alert appears to be triggered by synthetic bridge method scaffolding
that Kotlin generates foropen valproperties, which the Java extractor
misidentifies as a field declaration in the subclass
Related
This appears to be in the same category as PR #10859 which excluded Kotlin Live Literals from this same rule:
https://github.com/github/codeql/pull/10859
That PR acknowledged that Kotlin-generated bytecode patterns can trigger false positives in java/field-masks-super-field. The sealed class + object + open val pattern appears to be another such case.
Workaround
Removing open from the constructor parameters eliminates the alert and is safe when no subclass actually overrides the properties. However
this forces unnecessary code changes to work around a false positive.
Expected Behaviour
The rule should not fire when no subclass explicitly redeclares the field in its body - consistent with how PR #10859 handled Live Literals.
- 主要言語
- CodeQL
- スター
- 10.1k
- フォーク
- 2.1k
- 平均マージ
- 2日 10時間
- マージ済み PR(30日)
- 134
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/codeql のほかの issue
-
難易度 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
-
false-positive
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
sipyourdrink-ltd/bernstein#6191 ·
-
security severity:low track:open-source
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
[addtool] DeepZero オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
gwen001/offsectools_www#2055 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
WalletConnect/actions#112 ·