False Positive: IterableIterator.ql reports classes whose `hasNext()` still reliably disables iteration.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- java
- Domain
- security, testing-qa
Research direction
Start with the Language Abuse/IterableIterator.ql checker and the affected NegCase6_Var2.java and NegCase6_Var4.java test cases. Trace how hasNext() is recognized when it returns false through a helper or constant, then update the checker tests so these cases are no longer reported while the unsafe self-iterable cases remain covered.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- CodeQL
- Stars
- 10.1k
- Forks
- 2.1k
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 143
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from github/codeql
-
agentic-workflows
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
false-positive javascript
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
false-positive
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
punkpeye/mcp-remote#369 ·
-
Mend: dependency security vulnerability untriaged
Difficulty 1/5 Under an hour Newbie friendliness 86/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
cisagov/vulnrichment#337 ·
-
bug DUP Reservations
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
bcgov/reserve-rec-public#896 ·