changeset 1560:6794e1f16729

6461173: One JCK test([NewFolderAction0001]) failed on Windows due to lack of PropertyPermission(s) Reviewed-by: peterz, malenkov
author rupashka
date Mon, 10 Aug 2009 14:55:10 +0400
parents 082ffa4c6749
children 8e65977e4969
files src/share/classes/javax/swing/filechooser/FileSystemView.java src/windows/classes/sun/awt/shell/Win32ShellFolder2.java src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java
diffstat 3 files changed, 36 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/swing/filechooser/FileSystemView.java	Fri Aug 07 19:06:56 2009 +0400
+++ b/src/share/classes/javax/swing/filechooser/FileSystemView.java	Mon Aug 10 14:55:10 2009 +0400
@@ -37,6 +37,8 @@
 import java.lang.ref.WeakReference;
 import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeEvent;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import sun.awt.shell.*;
 
@@ -718,8 +720,13 @@
         return isFileSystemRoot(dir);
     }
 
-    public boolean isFloppyDrive(File dir) {
-        String path = dir.getAbsolutePath();
+    public boolean isFloppyDrive(final File dir) {
+        String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
+            public String run() {
+                return dir.getAbsolutePath();
+            }
+        });
+
         return (path != null && (path.equals("A:\\") || path.equals("B:\\")));
     }
 
--- a/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Fri Aug 07 19:06:56 2009 +0400
+++ b/src/windows/classes/sun/awt/shell/Win32ShellFolder2.java	Mon Aug 10 14:55:10 2009 +0400
@@ -73,12 +73,7 @@
 
     private static native void initIDs();
 
-    private static final boolean is98;
-
     static {
-        String osName = System.getProperty("os.name");
-        is98 = (osName != null && osName.startsWith("Windows 98"));
-
         initIDs();
     }
 
@@ -305,7 +300,6 @@
             }, RuntimeException.class)
         );
         this.disposer.relativePIDL = relativePIDL;
-        getAbsolutePath();
         sun.java2d.Disposer.addRecord(this, disposer);
     }
 
@@ -616,11 +610,8 @@
     public boolean isDirectory() {
         if (isDir == null) {
             // Folders with SFGAO_BROWSABLE have "shell extension" handlers and are
-            // not traversable in JFileChooser. An exception is "My Documents" on
-            // Windows 98.
-            if (hasAttribute(ATTRIB_FOLDER)
-                && (!hasAttribute(ATTRIB_BROWSABLE) ||
-                    (is98 && equals(Win32ShellFolderManager2.getPersonal())))) {
+            // not traversable in JFileChooser.
+            if (hasAttribute(ATTRIB_FOLDER) && !hasAttribute(ATTRIB_BROWSABLE)) {
                 isDir = Boolean.TRUE;
             } else if (isLink()) {
                 ShellFolder linkLocation = getLinkLocation(false);
--- a/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java	Fri Aug 07 19:06:56 2009 +0400
+++ b/src/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java	Mon Aug 10 14:55:10 2009 +0400
@@ -105,9 +105,11 @@
     private static Win32ShellFolder2 network;
     private static Win32ShellFolder2 personal;
 
-    private static String osVersion = System.getProperty("os.version");
-    private static final boolean useShell32Icons =
-                        (osVersion != null && osVersion.compareTo("5.1") >= 0);
+    private static final boolean USE_SHELL32_ICONS = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+        public Boolean run() {
+            return OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) >= 0;
+        }
+    });
 
     static Win32ShellFolder2 getDesktop() {
         if (desktop == null) {
@@ -307,15 +309,15 @@
                 i = Integer.parseInt(name);
             } catch (NumberFormatException ex) {
                 if (name.equals("ListView")) {
-                    i = (useShell32Icons) ? 21 : 2;
+                    i = (USE_SHELL32_ICONS) ? 21 : 2;
                 } else if (name.equals("DetailsView")) {
-                    i = (useShell32Icons) ? 23 : 3;
+                    i = (USE_SHELL32_ICONS) ? 23 : 3;
                 } else if (name.equals("UpFolder")) {
-                    i = (useShell32Icons) ? 28 : 8;
+                    i = (USE_SHELL32_ICONS) ? 28 : 8;
                 } else if (name.equals("NewFolder")) {
-                    i = (useShell32Icons) ? 31 : 11;
+                    i = (USE_SHELL32_ICONS) ? 31 : 11;
                 } else if (name.equals("ViewMenu")) {
-                    i = (useShell32Icons) ? 21 : 2;
+                    i = (USE_SHELL32_ICONS) ? 21 : 2;
                 }
             }
             if (i >= 0) {
@@ -352,11 +354,16 @@
      * Does <code>dir</code> represent a "computer" such as a node on the network, or
      * "My Computer" on the desktop.
      */
-    public boolean isComputerNode(File dir) {
+    public boolean isComputerNode(final File dir) {
         if (dir != null && dir == getDrives()) {
             return true;
         } else {
-            String path = dir.getAbsolutePath();
+            String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
+                public String run() {
+                    return dir.getAbsolutePath();
+                }
+            });
+
             return (path.startsWith("\\\\") && path.indexOf("\\", 2) < 0);      //Network path
         }
     }
@@ -501,7 +508,7 @@
                 // thread, we don't need to delegate the task
                 return task.call();
             } else {
-                Future<T> future;
+                final Future<T> future;
 
                 try {
                     future = submit(task);
@@ -512,7 +519,13 @@
                 try {
                     return future.get();
                 } catch (InterruptedException e) {
-                    future.cancel(true);
+                    AccessController.doPrivileged(new PrivilegedAction<Void>() {
+                        public Void run() {
+                            future.cancel(true);
+
+                            return null;
+                        }
+                    });
 
                     throw e;
                 } catch (ExecutionException e) {