False positive: java/field-masks-super-field triggered on Kotlin sealed class with open val constructor parameters
還沒有人認領這個 Issue。
評估
研究方向
從 Kotlin 重現和 java/field-masks-super-field 查詢開始,然後將其處理方式與關於 Kotlin Live Literals 的 PR #10859 進行比較。確認 Java extractor 如何表示 sealed class、object subclasses 和 open val parameters。完成的標準是:針對這種模式抑制 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 小時
- 30 天內合併 PR
- 134
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/codeql 的其他 Issue
-
難度 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
-
false-positive
難度 3/5 1-2 天 新手友好度 68/100
相似的 Issue
-
Product: Azure Policy :shield: Topic: Diagnostic Settings :test_tube: Topic: Policy :pencil:
難度 1/5 1-3 小時 新手友好度 92/100
Azure/Azure-Landing-Zones#4283 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 88/100
MystenLabs/MemWal#979 · 1 則留言 ·
-
namespace operations
難度 1/5 1 小時以內 新手友好度 82/100
EclipseFdn/open-vsx.org#13384 ·
-
難度 2/5 1-3 小時 新手友好度 76/100
-
documentation
難度 2/5 半天 新手友好度 62/100
inmanta/inmanta-core#10835 ·