False Positive: IterableIterator.ql reports classes whose `hasNext()` still reliably disables iteration.
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- java
- Ambito
- security, testing-qa
Direzione di ricerca
Inizia con il checker Language Abuse/IterableIterator.ql e con i casi di test interessati NegCase6_Var2.java e NegCase6_Var4.java. Traccia il modo in cui hasNext() viene riconosciuto quando restituisce false tramite un helper o una costante, quindi aggiorna i test del checker in modo che questi casi non vengano più segnalati, mantenendo comunque la copertura dei casi self-iterable non sicuri.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
False Positive: IterableIterator.ql reports classes whose hasNext() still reliably disables iteration.
Version
codeql 2.24.3
Checker
- Checker id:
Language Abuse/IterableIterator.ql - Checker description: This checker detects classes that implement Iterable by returning themselves as the Iterator but lack a guard to prevent multiple concurrent iterations.
Description of the false positive
These classes do return this from iterator(), but hasNext() still deterministically returns false, which is exactly the built-in guard that keeps iteration from proceeding. The refactoring only changes how that false result is computed.
Affected test cases
NegCase6_Var2.java
hasNext() still disables reuse of the iterator instance in practice, so this should not be reported as an unsafe self-iterable.
// A concrete class that implements Iterable, returns "this" in iterator(), and has hasNext() returning false should not be flagged.
package scensct.var.neg;
import java.util.Iterator;
public class NegCase6_Var2 implements Iterable<Double>, Iterator<Double> { // [REPORTED LINE]
public Iterator<Double> iterator() {
return this;
}
private boolean neverHasNext() {
return false;
}
public boolean hasNext() {
return neverHasNext();
}
public Double next() {
return 0.0;
}
}
NegCase6_Var4.java
The iteration guard is still present even though the control flow is slightly different.
// A concrete class that implements Iterable, returns "this" in iterator(), and has hasNext() returning false should not be flagged.
package scensct.var.neg;
import java.util.Iterator;
public class NegCase6_Var4 implements Iterable<Double>, Iterator<Double> { // [REPORTED LINE]
private final boolean NO_MORE = false;
public Iterator<Double> iterator() {
return this;
}
public boolean hasNext() {
for (int i = 0; i < 1; i++) {
// loop does nothing
}
return NO_MORE;
}
public Double next() {
return 0.0;
}
}
Cause analysis
The query appears too literal about what counts as a valid guard. Once hasNext() returns false via a helper or a constant field instead of a bare literal, the class is still reported.
That is overly rigid. The safety property here is semantic: iteration is disabled, regardless of whether false is returned directly or indirectly.
References
None known.
- Lingua principale
- CodeQL
- Stelle
- 10.1k
- Fork
- 2.1k
- Merge medio
- 2g 16h
- PR unite (30g)
- 143
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
-
agentic-workflows
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
false-positive javascript
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
Tutte le issue di github/codeql
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
canonical/paas-charm#368 · 1 commento ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
palladius/rails8-app-on-gcp#142 ·
-
addition to tracking list Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
StevenBlack/hosts#3256 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
corsairdev/corsair#1764 ·
-
oblt-aw/detector/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100