From 60efe949917999c74dc6061b371942dd3ab8d7d1 Mon Sep 17 00:00:00 2001 From: Jean-Marie Burel Date: Wed, 5 Jan 2022 11:47:14 +0000 Subject: [PATCH 1/2] use toURI method to handle --- .../shoola/util/ui/filechooser/GenericFileChooser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/openmicroscopy/shoola/util/ui/filechooser/GenericFileChooser.java b/src/main/java/org/openmicroscopy/shoola/util/ui/filechooser/GenericFileChooser.java index d6b891757..d2987afc7 100644 --- a/src/main/java/org/openmicroscopy/shoola/util/ui/filechooser/GenericFileChooser.java +++ b/src/main/java/org/openmicroscopy/shoola/util/ui/filechooser/GenericFileChooser.java @@ -64,7 +64,7 @@ public class GenericFileChooser private void handleFileSelection(File f) { if (box == null || f == null) return; - if (Files.isSymbolicLink(Paths.get(f.getAbsolutePath())) || f.getName().endsWith(".lnk")) { + if (Files.isSymbolicLink(Paths.get(f.toURI())) || f.getName().endsWith(".lnk")) { JOptionPane.showMessageDialog(null, "Cannot use shortcut " + "from selection box."); box.setSelectedItem(f.getParentFile()); From 8fc2d724af88dc3c35556fc4d2fa325fd2465388 Mon Sep 17 00:00:00 2001 From: Dominik Lindner Date: Wed, 19 Jan 2022 13:23:24 +0000 Subject: [PATCH 2/2] Catch InvalidPathException --- .../ui/filechooser/GenericFileChooser.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/openmicroscopy/shoola/util/ui/filechooser/GenericFileChooser.java b/src/main/java/org/openmicroscopy/shoola/util/ui/filechooser/GenericFileChooser.java index d2987afc7..12568750d 100644 --- a/src/main/java/org/openmicroscopy/shoola/util/ui/filechooser/GenericFileChooser.java +++ b/src/main/java/org/openmicroscopy/shoola/util/ui/filechooser/GenericFileChooser.java @@ -1,6 +1,6 @@ /* *------------------------------------------------------------------------------ - * Copyright (C) 2006-2011 University of Dundee & Open Microscopy Environment. + * Copyright (C) 2006-2022 University of Dundee & Open Microscopy Environment. * All rights reserved. * * @@ -25,6 +25,7 @@ import java.awt.event.ActionListener; import java.io.File; import java.nio.file.Files; +import java.nio.file.InvalidPathException; import java.nio.file.Paths; import javax.swing.JComboBox; import javax.swing.JFileChooser; @@ -63,11 +64,16 @@ public class GenericFileChooser */ private void handleFileSelection(File f) { - if (box == null || f == null) return; - if (Files.isSymbolicLink(Paths.get(f.toURI())) || f.getName().endsWith(".lnk")) { - JOptionPane.showMessageDialog(null, "Cannot use shortcut " + - "from selection box."); - box.setSelectedItem(f.getParentFile()); + if (box == null || f == null) + return; + try { + if (Files.isSymbolicLink(Paths.get(f.toURI())) || f.getName().endsWith(".lnk")) { + JOptionPane.showMessageDialog(null, "Cannot use shortcut " + + "from selection box."); + box.setSelectedItem(f.getParentFile()); + } + } catch (InvalidPathException e) { + // this is thrown on Windows 10 when "This PC" selected, just ignore. } }