Skip to content

A False Negative in INEFFICIENT_KEYSET_ITERATOR Detection​ #1948

@RJerrica

Description

@RJerrica

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  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions