changeset 6255:b1a2b9ac9714

8004288: (fs) Files.probeContentType problems Reviewed-by: ahgross, sherman
author alanb
date Wed, 27 Feb 2013 11:50:30 +0000
parents 1111f9acb96b
children c450b20e8030
files src/share/classes/java/nio/file/Files.java src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/nio/file/Files.java	Wed Feb 27 11:53:10 2013 +0400
+++ b/src/share/classes/java/nio/file/Files.java	Wed Feb 27 11:50:30 2013 +0000
@@ -1484,10 +1484,19 @@
     // lazy loading of default and installed file type detectors
     private static class FileTypeDetectors{
         static final FileTypeDetector defaultFileTypeDetector =
-            sun.nio.fs.DefaultFileTypeDetector.create();
+            createDefaultFileTypeDetector();
         static final List<FileTypeDetector> installeDetectors =
             loadInstalledDetectors();
 
+        // creates the default file type detector
+        private static FileTypeDetector createDefaultFileTypeDetector() {
+            return AccessController
+                .doPrivileged(new PrivilegedAction<FileTypeDetector>() {
+                    @Override public FileTypeDetector run() {
+                        return sun.nio.fs.DefaultFileTypeDetector.create();
+                }});
+        }
+
         // loads all installed file type detectors
         private static List<FileTypeDetector> loadInstalledDetectors() {
             return AccessController
--- a/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java	Wed Feb 27 11:53:10 2013 +0400
+++ b/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java	Wed Feb 27 11:50:30 2013 +0000
@@ -67,6 +67,8 @@
         NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls());
         try {
             if (gioAvailable) {
+                // GIO may access file so need permission check
+                path.checkRead();
                 byte[] type = probeUsingGio(buffer.address());
                 return (type == null) ? null : new String(type);
             } else {
@@ -76,7 +78,6 @@
                 String s = new String(type);
                 return s.equals(GNOME_VFS_MIME_TYPE_UNKNOWN) ? null : s;
             }
-
         } finally {
             buffer.release();
         }