Changeset 18634 in josm


Ignore:
Timestamp:
2023-01-16T16:52:10+01:00 (18 months ago)
Author:
taylor.smock
Message:

Fix #22638: NoSuchFileException can occur when a gpx track points at non-existent images

Location:
trunk
Files:
2 edited

Legend:

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

    r18613 r18634  
    55
    66import java.awt.event.ActionEvent;
     7import java.io.UncheckedIOException;
    78import java.net.URI;
    89import java.net.URISyntaxException;
     
    6768        } catch (URISyntaxException e) {
    6869            Logging.trace(e);
    69             new Notification(tr("Malformed URI: ", this.imageUrl.toExternalForm())).setIcon(JOptionPane.WARNING_MESSAGE).show();
     70            new Notification(tr("Malformed URI: {0}", this.imageUrl.toExternalForm())).setIcon(JOptionPane.WARNING_MESSAGE).show();
     71        } catch (UncheckedIOException e) {
     72            Logging.trace(e);
     73            new Notification(tr("IO Exception: {0}\n{1}", this.imageUrl.toExternalForm(), e.getCause().getMessage()))
     74                    .setIcon(JOptionPane.WARNING_MESSAGE).show();
    7075        }
    7176        return null;
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarkerTest.java

    r18593 r18634  
    22package org.openstreetmap.josm.gui.layer.markerlayer;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    45import static org.junit.jupiter.api.Assertions.assertEquals;
    56
     
    4041        assertEquals(LatLon.ZERO, wpt.getCoor());
    4142    }
     43
     44    /**
     45     * Non-regression test for #22638: NoSuchFileException causes a crash
     46     */
     47    @Test
     48    void testTicket22638() throws MalformedURLException {
     49        ImageMarker marker = new ImageMarker(
     50                LatLon.ZERO,
     51                new File(TestUtils.getRegressionDataFile(12255, "no_such.jpg")).toURI().toURL(),
     52                new MarkerLayer(new GpxData(), null, null, null),
     53                1d, 2d);
     54        assertDoesNotThrow(() -> marker.actionPerformed(null));
     55    }
    4256}
Note: See TracChangeset for help on using the changeset viewer.