Skip to content

Commit

Permalink
Fix #23866: java.io.UncheckedIOException: java.nio.file.FileSystemExc…
Browse files Browse the repository at this point in the history
…eption: The device is not ready

This does two things:
1. Unwrap an unchecked exception in ImagesLoader so that we are throwing a
   checked exception
2. Explain some IO exceptions (specifically "the device is not ready")

This is not the "best" solution, but it ''should'' mean that we are not ignoring
issues related to JOSM.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@19216 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Sep 9, 2024
1 parent 86382f4 commit 833fd93
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -143,6 +144,19 @@ public static void explainNestedIOException(OsmTransferException e) {
);
}

/**
* 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.
Expand Down Expand Up @@ -492,6 +506,11 @@ public static void explainException(Exception e) {
explainOsmTransferException((OsmTransferException) e);
return;
}
FileSystemException fileSystemException = ExceptionUtil.getNestedException(e, FileSystemException.class);
if (fileSystemException != null) {
explainIOException(fileSystemException);
return;
}
explainGeneric(e);
}
}
10 changes: 9 additions & 1 deletion src/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,7 +91,14 @@ protected void realRun() throws IOException {
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);
}
Expand Down

0 comments on commit 833fd93

Please sign in to comment.