False positive: java/field-masks-super-field triggered on Kotlin sealed class with open val constructor parameters
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 64/100
Direzione di ricerca
Inizia con la riproduzione Kotlin e la query java/field-masks-super-field, quindi confronta la relativa gestione con PR #10859 su Kotlin Live Literals. Verifica come la sealed class, le object subclasses e gli open val parameters vengono rappresentati dall’estrattore Java. Il lavoro è completato quando l’alert viene soppresso per questo pattern, mentre il field shadowing genuino continua a essere segnalato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- CodeQL
- Stelle
- 10.1k
- Fork
- 2.1k
- Merge medio
- 2g 11h
- PR unite (30g)
- 129
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di github/codeql
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
false-positive
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
False positive Apertafalse-positive
Difficoltà 4/5 3-5 giorni Idoneità per principianti 15/100
Tutte le issue di github/codeql
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
avniproject/avni-client#2135 ·
-
agent/security hive/hosted-available-lke648397-260827-5n31 security
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
api7/lua-resty-saml#63 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100