infer icon indicating copy to clipboard operation
infer copied to clipboard

A False Negative in INEFFICIENT_KEYSET_ITERATOR Detection​

Open RJerrica opened this issue 2 months ago • 0 comments

In the following code example, there is an INEFFICIENT_KEYSET_ITERATOR issue at line 8. However, Infer fails to report this warning, resulting in a false negative.

Minimized Code Example

import java.util.HashMap;
public class Main {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.keySet()
            .forEach(
                key -> {
                    String s = map.get(key); // should report a warning, but no warnings
                    if (s.equals("foo")) {
                        System.out.println("true");
                    }
                });
    }
}

Analysis Log

Capturing in javac mode...
Found 1 source file to analyze in /.../infer-out
0/8 [................................................................................] 0% 116ms
⊢ [ 0.1s][ 8.8M] idle
⊢ [ 0.1s][ 8.8M] idle
4/8 [########################################........................................] 50% 184ms
⊢ [ 0.0s][ 8.8M] Main.java
⊢ [ 0.2s][ 8.8M] idle
8/8 [################################################################################] 100% 192ms
⊢ [ 0.0s][ 8.8M] idle
⊢ [ 0.0s][ 8.8M] idle
⊢ [ 0.0s][10.2M] idle

  No issues found  

RJerrica avatar Oct 07 '25 08:10 RJerrica