Changeset 18390 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2022-03-09T09:19:18+01:00 (3 years ago)
Author:
GerdP
Message:

see #21740: IAE: Attempted to add listener that was already in list: external preset with group name RoadSigns

  • improve check for repeatedly registered ActiveLayerChangeListener: check for identity instead of equality, log error with traceback (similar to EDT violations) instead of throwing an IllegalArgumentException
File:
1 edited

Legend:

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

    r18337 r18390  
    174174     */
    175175    public synchronized void addActiveLayerChangeListener(ActiveLayerChangeListener listener) {
    176         if (activeLayerChangeListeners.contains(listener)) {
    177             throw new IllegalArgumentException("Attempted to add listener that was already in list: " + listener);
     176        for (int i = 0; i< activeLayerChangeListeners.size(); i++) {
     177            if (activeLayerChangeListeners.get(i) == listener) {
     178                Logging.error("");
     179                Logging.error("Attempted to add listener that was already in list: " + listener);
     180                showStackTrace(Thread.currentThread().getStackTrace());
     181                return;
     182            }
    178183        }
    179184        activeLayerChangeListeners.add(listener);
     185    }
     186
     187    private void showStackTrace(StackTraceElement[] stackTrace) {
     188        for (StackTraceElement st : stackTrace) {
     189            Logging.error("\tat " + st);
     190        }
    180191    }
    181192
     
    195206     */
    196207    public synchronized void removeActiveLayerChangeListener(ActiveLayerChangeListener listener) {
    197         if (!activeLayerChangeListeners.contains(listener)) {
    198             throw new IllegalArgumentException("Attempted to remove listener that was not in list: " + listener);
    199         }
    200         activeLayerChangeListeners.remove(listener);
     208        int old = -1;
     209        for (int i = 0; i < activeLayerChangeListeners.size(); i++) {
     210            if (activeLayerChangeListeners.get(i) == listener) {
     211                old = i;
     212                break;
     213            }
     214        }
     215        if (old < 0) {
     216            Logging.error("");
     217            Logging.error("Attempted to remove listener that was not in list: " + listener);
     218            showStackTrace(Thread.currentThread().getStackTrace());
     219            return;
     220        }
     221        activeLayerChangeListeners.remove(old);
    201222    }
    202223
     
    207228     */
    208229    public synchronized void addLayerAvailabilityListener(LayerAvailabilityListener listener) {
    209         if (!layerAvailabilityListeners.add(listener)) {
    210             throw new IllegalArgumentException("Attempted to add listener that was already in list: " + listener);
    211         }
     230        layerAvailabilityListeners.add(listener);
    212231    }
    213232
Note: See TracChangeset for help on using the changeset viewer.