WMI_WRONG_MAP_ITERATOR: But I need key/value

  • Nick Stolwijk

    Nick Stolwijk - 2005-11-10

    FindBugs is complaining of my use of the Map iterators keySet().iterator and get(key).

    But I do need the key and the value to work with. Did I take the wrong collection, or did I do something else wrong?

    Sample code:
                for (final Iterator iter = propertyMap.keySet().iterator(); iter
                        .hasNext();) {
                    final String name = (String) iter.next();
                    final String value = (String) propertyMap.get(name);
                    //Do something with key and value

    • Dave Brosius

      Dave Brosius - 2005-11-14

      Use an entrySet iterator when you need key and value: So do:

      for (final Iterator iter = propertyMap.entrySet().iterator(); iter.hasNext();) {
         Map.Entry entry = iter.next();
         final String name = entry.getKey();
         final String value = entry.getValue();
         // do something

      this avoids the map lookup (get) each time thru the loop.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks