False positive for "Iterate over the "entrySet" instead of the "keySet"."

306 views
Skip to first unread message

mikael petterson

unread,
Oct 17, 2017, 2:18:43 AM10/17/17
to SonarQube
Hi,

We got the following in sonar:



What are we missing? Or is it a false positive in Sonar.

We use SonarQube Version 5.6.6.

br,

//mikael


Auto Generated Inline Image 1

simon schrottner

unread,
Oct 17, 2017, 3:05:30 AM10/17/17
to SonarQube
hi

i highly recommend to also post your SonarJava version, so it is possible to tell you, if you are maybe just using an outdated version of sonarJava :D

Br
Simon

mikael petterson

unread,
Oct 17, 2017, 6:02:48 AM10/17/17
to SonarQube
SonarJava 4.7.1.9272

br,

//mikael

G. Ann Campbell

unread,
Oct 17, 2017, 9:01:01 AM10/17/17
to SonarQube
Hi mikael, 

You are indeed using a rather dusty version of SonarJava. Please give it a try with the latest: 4.14.


Ann

mikael petterson

unread,
Oct 18, 2017, 3:21:29 AM10/18/17
to SonarQube
Can you confirm that this issue has been fixed in later versions. I am asking this since the process to get a new version of SonarJava requires a lot of coordination and weekend work.

br,

//mikael

Nicolas Peru

unread,
Oct 18, 2017, 4:21:50 AM10/18/17
to mikael petterson, SonarQube
Hi, 

 Could you provide a simple reproducer of the issue so we can investigate properly ? 

Cheers, 

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/ad05b95c-f88c-451d-ba03-cfc1b0c3dcd1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource

mikael petterson

unread,
Oct 19, 2017, 1:08:02 AM10/19/17
to SonarQube

Hi,

We tried with the following example:


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class LoopMap {

    public static void main(String[] args) {

        // initial a Map
        Map<String, String> map = new HashMap<String, String>();
        map.put("1", "Jan");
        map.put("2", "Feb");
        map.put("3", "Mar");
        map.put("4", "Apr");
        map.put("5", "May");
        map.put("6", "Jun");

        // more elegant way, this should be the standard way, recommend!
        System.out.println("\nExample 2...");
        for (Map.Entry<String, String> entry : map.entrySet()) {
            System.out.println("Key : " + entry.getKey() + " Value : " + entry.getValue());
        }

    }

}

but could not get a sonar warning. So I guess it must be an issue with the environment.

br,

//mikael
Reply all
Reply to author
Forward
0 new messages