From 9aefc3174cf689466216e8aeb11159ec15a58311 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Thu, 13 Mar 2014 11:49:24 +0400 Subject: [PATCH] 8035699: File choosers should be choosier Reviewed-by: alexsch, art, skoivu --- .../javax/swing/filechooser/FileSystemView.java | 3 ++- .../classes/sun/awt/shell/Win32ShellFolder2.java | 9 ++++++++- .../sun/awt/shell/Win32ShellFolderManager2.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/jdk/src/share/classes/javax/swing/filechooser/FileSystemView.java b/jdk/src/share/classes/javax/swing/filechooser/FileSystemView.java index 26f09eac229..f11827b6df1 100644 --- a/jdk/src/share/classes/javax/swing/filechooser/FileSystemView.java +++ b/jdk/src/share/classes/javax/swing/filechooser/FileSystemView.java @@ -739,7 +739,8 @@ class WindowsFileSystemView extends FileSystemView { * @return the Desktop folder. */ public File getHomeDirectory() { - return getRoots()[0]; + File[] roots = getRoots(); + return (roots.length == 0) ? null : roots[0]; } /** diff --git a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java index 42975132b15..ed3478d0be3 100644 --- a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java +++ b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java @@ -583,11 +583,18 @@ final class Win32ShellFolder2 extends ShellFolder { // Needs to be accessible to Win32ShellFolderManager2 static String getFileSystemPath(final int csidl) throws IOException, InterruptedException { - return invoke(new Callable() { + String path = invoke(new Callable() { public String call() throws IOException { return getFileSystemPath0(csidl); } }, IOException.class); + if (path != null) { + SecurityManager security = System.getSecurityManager(); + if (security != null) { + security.checkRead(path); + } + } + return path; } // NOTE: this method uses COM and must be called on the 'COM thread'. See ComInvoker for the details diff --git a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java index 6c1f4a9a89c..a5e4c965d89 100644 --- a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java +++ b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java @@ -136,6 +136,8 @@ final class Win32ShellFolderManager2 extends ShellFolderManager { if (desktop == null) { try { desktop = new Win32ShellFolder2(DESKTOP); + } catch (SecurityException e) { + // Ignore error } catch (IOException e) { // Ignore error } catch (InterruptedException e) { @@ -149,6 +151,8 @@ final class Win32ShellFolderManager2 extends ShellFolderManager { if (drives == null) { try { drives = new Win32ShellFolder2(DRIVES); + } catch (SecurityException e) { + // Ignore error } catch (IOException e) { // Ignore error } catch (InterruptedException e) { @@ -165,6 +169,8 @@ final class Win32ShellFolderManager2 extends ShellFolderManager { if (path != null) { recent = createShellFolder(getDesktop(), new File(path)); } + } catch (SecurityException e) { + // Ignore error } catch (InterruptedException e) { // Ignore error } catch (IOException e) { @@ -178,6 +184,8 @@ final class Win32ShellFolderManager2 extends ShellFolderManager { if (network == null) { try { network = new Win32ShellFolder2(NETWORK); + } catch (SecurityException e) { + // Ignore error } catch (IOException e) { // Ignore error } catch (InterruptedException e) { @@ -201,6 +209,8 @@ final class Win32ShellFolderManager2 extends ShellFolderManager { personal.setIsPersonal(); } } + } catch (SecurityException e) { + // Ignore error } catch (InterruptedException e) { // Ignore error } catch (IOException e) {