Ticket #23866: 23866.patch

File 23866.patch, 3.3 KB (added by taylor.smock, 20 months ago)
  • src/org/openstreetmap/josm/gui/layer/geoimage/ImagesLoader.java

    Subject: [PATCH] Fix #23866: java.io.UncheckedIOException: java.nio.file.FileSystemException: The device is not ready
    ---
    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 b  
    55
    66import java.io.File;
    77import java.io.IOException;
     8import java.io.UncheckedIOException;
    89import java.util.ArrayList;
    910import java.util.Arrays;
    1011import java.util.Collection;
     
    9091            progressMonitor.worked(1);
    9192
    9293            ImageEntry e = new ImageEntry(f);
    93             e.extractExif();
     94            try {
     95                e.extractExif();
     96            } catch (UncheckedIOException uncheckedIOException) {
     97                // We want to throw the actual IOException that is wrapped, not the unchecked IO exception.
     98                // See #23866
     99                Logging.trace(uncheckedIOException);
     100                throw uncheckedIOException.getCause();
     101            }
    94102            File parentFile = f.getParentFile();
    95103            entries.computeIfAbsent(parentFile != null ? parentFile.getName() : "", x -> new ArrayList<>()).add(e);
    96104        }
  • 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 b  
    99import java.net.HttpURLConnection;
    1010import java.net.SocketException;
    1111import java.net.UnknownHostException;
     12import java.nio.file.FileSystemException;
    1213import java.util.regex.Matcher;
    1314import java.util.regex.Pattern;
    1415
     
    143144        );
    144145    }
    145146
     147    /**
     148     * Explains a {@link IOException}
     149     *
     150     * @param e the exception
     151     */
     152    private static void explainIOException(Exception e) {
     153        if (e instanceof FileSystemException && e.getMessage().contains("The device is not ready")) {
     154            showErrorDialog(ExceptionUtil.explainException(e), tr("File System Exception"), null);
     155        } else {
     156            explainGeneric(e);
     157        }
     158    }
     159
    146160    /**
    147161     * Explains a {@link IllegalDataException} which has caused an {@link OsmTransferException}.
    148162     * This is most likely happening when JOSM tries to load data in an unsupported format.
     
    491505        if (e instanceof OsmTransferException) {
    492506            explainOsmTransferException((OsmTransferException) e);
    493507            return;
     508        }
     509        FileSystemException fileSystemException = ExceptionUtil.getNestedException(e, FileSystemException.class);
     510        if (fileSystemException != null) {
     511            explainIOException(fileSystemException);
     512            return;
    494513        }
    495514        explainGeneric(e);
    496515    }