java/non-final-call-in-constructor: a call made inside a lambda in the constructor is not reported
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
The report points at the unqualifiedCallToNonAbstractMethod predicate, which requires the call's enclosing callable to be the constructor (result.getEnclosingCallable() = c), so a call inside a lambda is missed. Start from the query java/non-final-call-in-constructor and the two seed files, CtorSeed.java and CtorVariant.java, and run the query on each database to confirm the gap. Done means the lambda case is reported at line 6 of CtorVariant.java while the existing results on CtorSeed.java stay the same.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description of the issue
The query reports toString() in the constructor of CtorSeed.Senior: Junior overrides it, the override reads name, and name is only assigned after super() returns, so new Junior() throws. Move the call into a lambda that the constructor runs right away (CtorVariant) and nothing is reported, though the call still happens during construction with the same effect.
Probably unqualifiedCallToNonAbstractMethod, which requires the call's enclosing callable to be the constructor (result.getEnclosingCallable() = c). Inside the lambda the enclosing callable is the lambda's own method.
Query: java/non-final-call-in-constructor (codeql/java-queries 1.1.10)
CodeQL CLI: 2.27.2
Code samples
seed/CtorSeed.java:
public class CtorSeed {
public static class Senior {
public Senior() {
toString(); // overridden in Junior, reads a field not yet set
}
public String toString() {
return "Senior";
}
}
public static class Junior extends Senior {
private String name;
public Junior() {
super();
name = "Junior";
}
public String toString() {
return name.toUpperCase(); // NullPointerException when called from Senior()
}
}
}
variant/CtorVariant.java:
public class CtorVariant {
public static class Senior {
public Senior() {
Runnable r = () -> {
toString(); // the same call, inside a lambda run at once; not reported
};
r.run();
}
public String toString() {
return "Senior";
}
}
public static class Junior extends Senior {
private String name;
public Junior() {
super();
name = "Junior";
}
public String toString() {
return name.toUpperCase();
}
}
}
How to reproduce
codeql database create db --language=java --build-mode=none \
--source-root=<one directory> --overwrite
codeql database analyze db \
codeql/java-queries:codeql-suites/java-security-and-quality.qls \
--format=csv --output=out.csv
# one database per directory
Expected result
"Non-final method invocation in constructor" on the toString() call inside the lambda in CtorVariant.java (line 6), as on CtorSeed.java (line 5).
Output of the commands above:
### CodeQL 2.27.2 query: java/non-final-call-in-constructor
### suite: java-security-and-quality.qls, --build-mode=none, per-file isolated databases
### extraction JDK: openjdk version "21.0.11" 2026-04-21 LTS
--- SEED -- expected: query fires (seed/)
"Non-final method invocation in constructor","If a constructor calls a method that is overridden in a subclass
--- VARIANT -- expected: query fires, actual: not reported (the bug) (variant/)
(query reported nothing)
- Vorherrschende Sprache
- CodeQL
- Sterne
- 10.3k
- Forks
- 2.1k
- Ø Merge
- 1 T. 22 Std.
- Gemergte PRs (30 T.)
- 126
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus github/codeql
-
JavaScript externs model StorageEvent() with no type argumentEvtl. vergeben @asgerf hat das vor 14 Tagen übernommen. Offenfalse-positive javascript
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
github/codeql#22632 · 3 Kommentare · 1 Reaktion · 2 zugewiesene Personen ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add AlertSuppression.ql for Rust (inline // codeql[...] suppression)Evtl. vergeben @cnuss hat das vor 215 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
github/codeql#21637 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
false-positive
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
github/codeql#21076 · 3 Kommentare · 3 Reaktionen ·
Maintainer antworten meist innerhalb von 1 Tag
-
General issueOffenquestion
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 5/100
Maintainer antworten meist innerhalb von 1 Tag
-
False positive java/local-variable-is-never-read for Kotlin data object-generated equals temporariesOffen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
emersion/go-msgauth#87 ·
-
Add unit tests for the organization admin role checkEvtl. vergeben @SaffuSafwan hat das heute übernommen. Offenarea/core good first issue help wanted
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
elmohq/elmo#1095 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
code-yeongyu/senpi#5713 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 1 Tag