Bug 58545

Summary: WsHandshakeRequest inefficient use of keySet
Product: Tomcat 8 Reporter: Anthony Whitford <anthony>
Component: WebSocketAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: trivial    
Priority: P2    
Version: 8.0.x-trunk   
Target Milestone: ----   
Hardware: Macintosh   
OS: Mac OS X 10.1   
Attachments: Replaces inefficient use of keySet() with more efficient entrySet()

Description Anthony Whitford 2015-10-25 22:49:41 UTC
Created attachment 33217 [details]
Replaces inefficient use of keySet() with more efficient entrySet()

In WsHandshakeRequest...

        for (String pathName : pathParams.keySet()) {
            newParameters.put(pathName,
                    Collections.unmodifiableList(
                            Arrays.asList(pathParams.get(pathName))));
        }


should be:

        for (Entry<String,String> entry : pathParams.entrySet()) {
            final String pathName = entry.getKey();
            newParameters.put(pathName,
                    Collections.unmodifiableList(
                            Arrays.asList(entry.getValue())));
        }

to avoid the extra lookup.

See http://findbugs.sourceforge.net/bugDescriptions.html#WMI_WRONG_MAP_ITERATOR
Comment 1 Violeta Georgieva 2015-10-26 17:39:29 UTC
Hi,

Thanks for the report and the patch.
I applied the same fix on other places in the code also.
The fix is available in trunk, 8.0.x (for 8.0.29 onwards) and 7.0.x (for 7.0.66
onwards)

Regards,
Violeta