Ticket #20950: 20950.patch

File 20950.patch, 1.3 KB (added by taylor.smock, 5 years ago)
  • src/org/openstreetmap/josm/gui/dialogs/LayerListPopup.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/LayerListPopup.java b/src/org/openstreetmap/josm/gui/dialogs/LayerListPopup.java
    index 68d3b77a8..a9a38a30c 100644
    a b import java.util.ArrayList;  
    1111import java.util.Arrays;
    1212import java.util.Collections;
    1313import java.util.List;
     14import java.util.stream.Collectors;
     15import java.util.stream.Stream;
    1416
    1517import javax.swing.AbstractAction;
    1618import javax.swing.Action;
    public class LayerListPopup extends JPopupMenu {  
    8183        List<Action> actions;
    8284        if (selectedLayers.size() == 1) {
    8385            Action[] entries = selectedLayers.get(0).getMenuEntries();
    84             actions = entries != null ? Arrays.asList(entries) : Collections.emptyList();
     86            // Since we may add to the array later, we cannot use Arrays.asList -- it prohibits the use of `add` or `remove`.
     87            actions = entries != null ? Stream.of(entries).collect(Collectors.toCollection(ArrayList::new)) : Collections.emptyList();
    8588        } else {
    8689            // Very simple algorithm - first selected layer has actions order as in getMenuEntries, actions from other layers go to the end
    8790            actions = new ArrayList<>();