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 天 11 小时
- 30 天内合并 PR
- 129
贡献指南
从这里开始
- 先读完整个 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 未关闭false-positive
难度 4/5 3-5 天 新手友好度 15/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
phoenixframework/phoenix#6847 ·
-
intake mcp-intake needs-ac needs-human-review priority:medium type:bug
难度 2/5 1-3 小时 新手友好度 84/100
Ikalus1988/MisakaNet#2019 · 2 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
avniproject/avni-client#2135 ·
-
agent/security hive/hosted-available-lke648397-260827-5n31 security
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 82/100
api7/lua-resty-saml#63 ·