facebook / facebook/infer

A false negative about the rule INEFFICIENT_KEYSET_ITERATOR

Open
#1,726 0 comments 1 reaction 0 assignees View on GitHub
false-negative java
Dominant language
OCaml
Stars
15.7k
Forks
2.1k
Avg merge
19h 36m
Merged PRs (30d)
13

Description

Infer version: v1.1.0
OS: Ubuntu 20

Command:
```bash
infer run --inefficient-keyset-iterator -- javac Example.java
```

The following code example can be detected:
```java
void inefficient_loop_itr_bad(HashMap testMap) {
Iterator itr2 = testMap.keySet().iterator();
while (itr2.hasNext()) {
String key = (String) itr2.next();
testMap.get(key); // can report a warning here
}
}
```
However, it cannot detect the do-while loop:
```java
void inefficient_loop_itr_bad(HashMap testMap) {
Iterator itr2 = testMap.keySet().iterator();
do {
String key = (String) itr2.next();
testMap.get(key); // no warnings at this line
} while (itr2.hasNext());
}
```

These two code examples are equivalent, hence, I think this is a false negative.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.