False positive java/local-variable-is-never-read for Kotlin data object-generated equals temporaries
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 35/100
研究方向
The false positive comes from the java/local-variable-is-never-read query (UnreadLocal.ql) reporting compiler-generated other_with_cast locals in zero-property Kotlin data object equals methods. Start by reproducing with the reduced LoadState source in a CodeQL database, then check how the query and the Kotlin extractor model generated locals. Done means these temporaries are excluded while genuinely unused user locals are still reported.
由索引模型根據 Issue 內容生成。
描述
Description of the false positive
java/local-variable-is-never-read reports Kotlin compiler-generated other_with_cast temporaries for zero-property data object declarations. The diagnostic is attached to the Kotlin file without a source region; GitHub displays line1. The application does not declare these variables or an equals implementation.
Environment actually observed
- CodeQL CLI 2.27.3, as selected by
github/codeql-actionv4.39.1 at9b3254085494b55a0f7c4c2b3d2d52cc712ce370. - Kotlin 2.4.21, JVM 27, Java/Kotlin manual build,
security-extendedwith the remote threat model. - The observations below come from a completed Android/Compose analysis and its SARIF, not an independently rerun CodeQL database for the reduced source below.
Reduced source
private sealed interface LoadState {
data object Loading : LoadState
data object Failed : LoadState
}
fun main() {
val states: List<LoadState> = listOf(LoadState.Loading, LoadState.Failed)
states.forEach { println(it) }
}
Observed SARIF diagnostic
Rule: java/local-variable-is-never-read
Level: note
Variable 'Loading tmp0_other_with_cast' is never read.
Variable 'Failed tmp0_other_with_cast' is never read.
Physical location: Kotlin source artifact, without a source region
The same analysis reports the same temporary-name pattern for two other zero-property data objects in another Kotlin source file.
Compiler and bytecode evidence
Kotlinv2.4.21 DataClassMembersGenerator.kt creates other_with_cast before iterating through properties. Reads occur within that loop. For a zero-property data object, the compiler-generated local therefore has no property read.
The Kotlin data-object contract specifies generated equals/hashCode implementations and prohibits supplying custom implementations. javap -p -c -l -v on both affected compiled classes confirms that equals(Object) exists despite being absent from application source; its LocalVariableTable contains only this and other after JVM lowering. No application declaration named tmp0_other_with_cast exists.
Expected behavior
Exclude this generated data-object equality temporary from the unread-source-local diagnostic, while retaining detection of genuinely unused user declarations.
Version-check limit
I did not execute a new CodeQL analysis with 2.27.4. Its official query is byte-identical to2.27.3 (UnreadLocal.ql SHA256 aae0d6fd7a2df5291352a3b2597cdff9e92a41f264e413801bb57ffbee071894), and the official Kotlin-extractor source subtree is identical (17c4961985b50180674d18fb4b12d64d3fd36b23). This is not a claim that an upgrade fixes or reproduces the issue; it records the inspected source boundaries.
The application has not been rewritten and the query has not been suppressed. The public example above contains no application-specific code, credentials or private repository references.
- 主要語言
- CodeQL
- 星號
- 10.3k
- 分支
- 2.1k
- 平均合併
- 1 天 22 小時
- 30 天內合併 PR
- 126
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/codeql 的其他 Issue
-
JavaScript externs model StorageEvent() with no type argument可能已有人在做 @asgerf 於 14 天前認領。 未關閉false-positive javascript
難度 2/5 1-3 小時 新手友好度 84/100
github/codeql#22632 · 3 則留言 · 1 個 reaction · 已指派 2 人 ·
維護者通常 1 天內回覆
-
Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)可能已有人在做 @cnuss 於 214 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
false-positive
難度 2/5 1-3 小時 新手友好度 70/100
github/codeql#21076 · 3 則留言 · 3 個 reaction ·
維護者通常 1 天內回覆
-
General issue未關閉question
難度 5/5 一週以上 新手友好度 5/100
維護者通常 1 天內回覆
-
java/unused-reference-type and java/unused-container: silenced by any annotation, even an empty one未關閉
難度 4/5 3-5 天 新手友好度 35/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 62/100
REditorSupport/languageserver#833 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
nolabs-ai/nono-packs#65 ·
-
bug
難度 2/5 1-3 小時 新手友好度 82/100
NousResearch/hermes-agent#148376 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
rescript-lang/rescript#9182 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 80/100