Changeset 6242 in josm for trunk


Ignore:
Timestamp:
2013-09-21T01:16:55+02:00 (11 years ago)
Author:
Don-vip
Message:

FindBugs - fix blocker issue (Performance - The equals and hashCode methods of URL are blocking)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r6084 r6242  
    1515import java.awt.event.MouseEvent;
    1616import java.io.File;
    17 import java.net.URL;
     17import java.net.URI;
     18import java.net.URISyntaxException;
    1819import java.util.ArrayList;
    1920import java.util.Collection;
     
    274275        double adjustment = AudioPlayer.position() - startMarker.offset; // in seconds
    275276        boolean seenStart = false;
    276         URL url = startMarker.url();
    277         for (Marker m : data) {
    278             if (m == startMarker) {
    279                 seenStart = true;
    280             }
    281             if (seenStart) {
    282                 AudioMarker ma = (AudioMarker) m; // it must be an AudioMarker
    283                 if (ma.url().equals(url)) {
    284                     ma.adjustOffset(adjustment);
    285                 }
    286             }
     277        try {
     278            URI uri = startMarker.url().toURI();
     279            for (Marker m : data) {
     280                if (m == startMarker) {
     281                    seenStart = true;
     282                }
     283                if (seenStart && m instanceof AudioMarker) {
     284                    AudioMarker ma = (AudioMarker) m;
     285                    // Do not ever call URL.equals but use URI.equals instead to avoid Internet connection
     286                    // See http://michaelscharf.blogspot.fr/2006/11/javaneturlequals-and-hashcode-make.html for details
     287                    if (ma.url().toURI().equals(uri)) {
     288                        ma.adjustOffset(adjustment);
     289                    }
     290                }
     291            }
     292        } catch (URISyntaxException e) {
     293            Main.warn("URISyntaxException: "+e.getMessage());
    287294        }
    288295        return true;
Note: See TracChangeset for help on using the changeset viewer.