Changeset 18927 in josm


Ignore:
Timestamp:
2023-12-27T22:09:21+01:00 (5 months ago)
Author:
taylor.smock
Message:

Fix #23316: MarkerLayer should return an empty list instead of a list with a single null value when the entry is null

Location:
trunk
Files:
2 edited

Legend:

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

    r18613 r18927  
    7676/**
    7777 * A layer holding markers.
    78  *
     78 * <p>
    7979 * Markers are GPS points with a name and, optionally, a symbol code attached;
    8080 * marker layers can be created from waypoints when importing raw GPS data,
    8181 * but they may also come from other sources.
    82  *
     82 * <p>
    8383 * The symbol code is for future use.
    84  *
     84 * <p>
    8585 * The data is read only.
    8686 */
     
    9595    private Marker currentMarker;
    9696    public AudioMarker syncAudioMarker;
    97     private Color color, realcolor;
     97    private Color color;
     98    private Color realcolor;
    9899    final int markerSize = new IntegerProperty("draw.rawgps.markers.size", 4).get();
    99100    final BasicStroke markerStroke = new StrokeProperty("draw.rawgps.markers.stroke", "1").get();
     
    523524    public List<? extends IImageEntry<?>> getSelection() {
    524525        if (this.currentMarker instanceof ImageMarker) {
    525             return Collections.singletonList(((ImageMarker) this.currentMarker).getRemoteEntry());
     526            final RemoteEntry remoteEntry = ((ImageMarker) this.currentMarker).getRemoteEntry();
     527            if (remoteEntry != null) {
     528                return Collections.singletonList(remoteEntry);
     529            }
    526530        }
    527531        return Collections.emptyList();
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayerTest.java

    r18870 r18927  
    77import static org.junit.jupiter.api.Assertions.assertTrue;
    88
     9import java.net.MalformedURLException;
     10import java.net.URI;
    911import java.util.Collections;
    1012
     
    9294        }
    9395    }
     96
     97    /**
     98     * Ensure that if a file is unable to be read, we return an empty list instead of a list with {@code null} in it.
     99     */
     100    @Test
     101    void testNonRegression23316() throws MalformedURLException {
     102        MarkerLayer layer = new MarkerLayer(new GpxData(), null, null, null);
     103        layer.setCurrentMarker(new ImageMarker(LatLon.ZERO, URI.create("file:/not_a_real_file_123456789.jpg").toURL(),
     104                layer, 0, 0));
     105        assertEquals(Collections.emptyList(), layer.getSelection());
     106    }
    94107}
Note: See TracChangeset for help on using the changeset viewer.