changeset 25536:a1ba79d447e0

8035699: File choosers should be choosier Reviewed-by: alexsch, art, skoivu
author malenkov
date Thu, 13 Mar 2014 11:49:24 +0400
parents 70b793c8273e
children 087de200d457
files jdk/src/share/classes/javax/swing/filechooser/FileSystemView.java jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
diffstat 3 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/share/classes/javax/swing/filechooser/FileSystemView.java	Thu Apr 24 21:00:52 2014 +0400
+++ b/jdk/src/share/classes/javax/swing/filechooser/FileSystemView.java	Thu Mar 13 11:49:24 2014 +0400
@@ -739,7 +739,8 @@
      * @return the Desktop folder.
      */
     public File getHomeDirectory() {
-        return getRoots()[0];
+        File[] roots = getRoots();
+        return (roots.length == 0) ? null : roots[0];
     }
 
     /**
--- a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Thu Apr 24 21:00:52 2014 +0400
+++ b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Thu Mar 13 11:49:24 2014 +0400
@@ -583,11 +583,18 @@
 
     // Needs to be accessible to Win32ShellFolderManager2
     static String getFileSystemPath(final int csidl) throws IOException, InterruptedException {
-        return invoke(new Callable<String>() {
+        String path = invoke(new Callable<String>() {
             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
--- a/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java	Thu Apr 24 21:00:52 2014 +0400
+++ b/jdk/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java	Thu Mar 13 11:49:24 2014 +0400
@@ -136,6 +136,8 @@
         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 @@
         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 @@
                 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 @@
         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 @@
                         personal.setIsPersonal();
                     }
                 }
+            } catch (SecurityException e) {
+                // Ignore error
             } catch (InterruptedException e) {
                 // Ignore error
             } catch (IOException e) {