diff --git a/src/org/openstreetmap/josm/gui/layer/geoimage/ImageMetadata.java b/src/org/openstreetmap/josm/gui/layer/geoimage/ImageMetadata.java index e678a472bc4..473e8e5752b 100644 --- a/src/org/openstreetmap/josm/gui/layer/geoimage/ImageMetadata.java +++ b/src/org/openstreetmap/josm/gui/layer/geoimage/ImageMetadata.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.io.UncheckedIOException; import java.net.URI; +import java.nio.file.FileSystemNotFoundException; import java.time.Instant; import java.util.List; @@ -261,7 +262,7 @@ default Integer getExifOrientation() { /** * Extract GPS metadata from image EXIF. Has no effect if the image file is not set - * + *

* If successful, fills in the LatLon, speed, elevation, image direction, and other attributes * @since 18592 (interface), 9270 (GpxImageEntry) */ @@ -271,6 +272,8 @@ default void extractExif() { ImageUtils.applyExif(this, bufferedInputStream); } catch (IOException e) { throw new UncheckedIOException(e); + } catch (IllegalArgumentException | FileSystemNotFoundException e) { + throw new UncheckedIOException(new IOException(e)); } } diff --git a/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarkerTest.java b/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarkerTest.java index 99bd426d69b..484b683a484 100644 --- a/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarkerTest.java +++ b/test/unit/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarkerTest.java @@ -6,6 +6,8 @@ import java.io.File; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -16,6 +18,7 @@ import org.openstreetmap.josm.gui.layer.geoimage.ImageViewerDialog; import org.openstreetmap.josm.testutils.annotations.BasicPreferences; import org.openstreetmap.josm.testutils.annotations.Main; +import org.openstreetmap.josm.tools.PlatformManager; /** * Unit tests of {@link ImageMarker} class. @@ -59,4 +62,23 @@ void testTicket22638() throws MalformedURLException { 1d, 2d); assertDoesNotThrow(() -> marker.actionPerformed(null)); } + + /** + * Windows does not like {@code :} to appear multiple times in a path. + * @throws MalformedURLException if the URI fails to create and convert to a URL. + */ + @Test + void testNonRegression23978() throws MalformedURLException { + final URL testURL; + if (PlatformManager.isPlatformWindows()) { + // This throws the InvalidPathException (subclass of IllegalArgumentException), and is what the initial problem was. + testURL = URI.create("file:/c:/foo/c:/bar/image.jpg").toURL(); + } else { + // This throws an IllegalArgumentException. + testURL = new URL("file:/foobar/image.jpg#hashtagForIAE"); + } + ImageMarker imageMarker = new ImageMarker(LatLon.ZERO, testURL, + new MarkerLayer(new GpxData(), null, null, null), 0, 0); + assertDoesNotThrow(() -> imageMarker.actionPerformed(null)); + } }