Subject: [PATCH] Fix #23866: java.io.UncheckedIOException: java.nio.file.FileSystemException: The device is not ready
---
Index: src/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoader.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoader.java b/src/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoader.java
--- a/src/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoader.java	(revision 19199)
+++ b/src/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoader.java	(date 1724105399246)
@@ -5,6 +5,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -90,7 +91,14 @@
             progressMonitor.worked(1);
 
             ImageEntry e = new ImageEntry(f);
-            e.extractExif();
+            try {
+                e.extractExif();
+            } catch (UncheckedIOException uncheckedIOException) {
+                // We want to throw the actual IOException that is wrapped, not the unchecked IO exception.
+                // See #23866
+                Logging.trace(uncheckedIOException);
+                throw uncheckedIOException.getCause();
+            }
             File parentFile = f.getParentFile();
             entries.computeIfAbsent(parentFile != null ? parentFile.getName() : "", x -> new ArrayList<>()).add(e);
         }
Index: src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java b/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
--- a/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java	(revision 19199)
+++ b/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java	(date 1724105468325)
@@ -9,6 +9,7 @@
 import java.net.HttpURLConnection;
 import java.net.SocketException;
 import java.net.UnknownHostException;
+import java.nio.file.FileSystemException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -143,6 +144,19 @@
         );
     }
 
+    /**
+     * Explains a {@link IOException}
+     *
+     * @param e the exception
+     */
+    private static void explainIOException(Exception e) {
+        if (e instanceof FileSystemException && e.getMessage().contains("The device is not ready")) {
+            showErrorDialog(ExceptionUtil.explainException(e), tr("File System Exception"), null);
+        } else {
+            explainGeneric(e);
+        }
+    }
+
     /**
      * Explains a {@link IllegalDataException} which has caused an {@link OsmTransferException}.
      * This is most likely happening when JOSM tries to load data in an unsupported format.
@@ -491,6 +505,11 @@
         if (e instanceof OsmTransferException) {
             explainOsmTransferException((OsmTransferException) e);
             return;
+        }
+        FileSystemException fileSystemException = ExceptionUtil.getNestedException(e, FileSystemException.class);
+        if (fileSystemException != null) {
+            explainIOException(fileSystemException);
+            return;
         }
         explainGeneric(e);
     }
