8194546: Choosier FileManagers
authorkaddepalli
Fri, 29 Jun 2018 10:28:05 +0530
changeset 52168 0c50240bf61d
parent 52167 b1db57cfe6bd
child 52169 ca48ad1b6e21
8194546: Choosier FileManagers Reviewed-by: serb, prr, rhalade, skoivu
src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java
src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
--- a/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Wed Jun 20 18:02:22 2018 -0700
+++ b/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Fri Jun 29 10:28:05 2018 +0530
@@ -736,7 +736,7 @@
         }
 
         try {
-            return invoke(new Callable<File[]>() {
+            File[] files = invoke(new Callable<File[]>() {
                 public File[] call() throws InterruptedException {
                     if (!isDirectory()) {
                         return null;
@@ -791,6 +791,8 @@
                         : list.toArray(new ShellFolder[list.size()]);
                 }
             }, InterruptedException.class);
+
+            return Win32ShellFolderManager2.checkFiles(files);
         } catch (InterruptedException e) {
             return new File[0];
         }
--- a/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java	Wed Jun 20 18:02:22 2018 -0700
+++ b/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java	Fri Jun 29 10:28:05 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -387,21 +387,30 @@
         return null;
     }
 
-    private File checkFile(File file) {
+    private static File checkFile(File file) {
         SecurityManager sm = System.getSecurityManager();
         return (sm == null || file == null) ? file : checkFile(file, sm);
     }
 
-    private File checkFile(File file, SecurityManager sm) {
+    private static File checkFile(File file, SecurityManager sm) {
         try {
             sm.checkRead(file.getPath());
+
+            if (file instanceof Win32ShellFolder2) {
+                Win32ShellFolder2 f = (Win32ShellFolder2)file;
+                if (f.isLink()) {
+                    Win32ShellFolder2 link = (Win32ShellFolder2)f.getLinkLocation();
+                    if (link != null)
+                        sm.checkRead(link.getPath());
+                }
+            }
             return file;
         } catch (SecurityException se) {
             return null;
         }
     }
 
-    private File[] checkFiles(File[] files) {
+    static File[] checkFiles(File[] files) {
         SecurityManager sm = System.getSecurityManager();
         if (sm == null || files == null || files.length == 0) {
             return files;
@@ -409,7 +418,7 @@
         return checkFiles(Arrays.stream(files), sm);
     }
 
-    private File[] checkFiles(List<File> files) {
+    private static File[] checkFiles(List<File> files) {
         SecurityManager sm = System.getSecurityManager();
         if (sm == null || files.isEmpty()) {
             return files.toArray(new File[files.size()]);
@@ -417,7 +426,7 @@
         return checkFiles(files.stream(), sm);
     }
 
-    private File[] checkFiles(Stream<File> filesStream, SecurityManager sm) {
+    private static File[] checkFiles(Stream<File> filesStream, SecurityManager sm) {
         return filesStream.filter((file) -> checkFile(file, sm) != null)
                 .toArray(File[]::new);
     }