From 013fa331c61b170b87d6ff2993931f64464dfb62 Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Wed, 27 Feb 2013 11:44:41 +0000 Subject: [PATCH] 8004288: (fs) Files.probeContentType problems Reviewed-by: ahgross, sherman --- jdk/src/share/classes/java/nio/file/Files.java | 11 ++++++++++- .../classes/sun/nio/fs/GnomeFileTypeDetector.java | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/jdk/src/share/classes/java/nio/file/Files.java b/jdk/src/share/classes/java/nio/file/Files.java index 2db7ba25c4a..3f55f7addde 100644 --- a/jdk/src/share/classes/java/nio/file/Files.java +++ b/jdk/src/share/classes/java/nio/file/Files.java @@ -1485,10 +1485,19 @@ public final class Files { // 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 installeDetectors = loadInstalledDetectors(); + // creates the default file type detector + private static FileTypeDetector createDefaultFileTypeDetector() { + return AccessController + .doPrivileged(new PrivilegedAction() { + @Override public FileTypeDetector run() { + return sun.nio.fs.DefaultFileTypeDetector.create(); + }}); + } + // loads all installed file type detectors private static List loadInstalledDetectors() { return AccessController diff --git a/jdk/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java b/jdk/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java index f92a31488f8..af3a47440e8 100644 --- a/jdk/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java +++ b/jdk/src/solaris/classes/sun/nio/fs/GnomeFileTypeDetector.java @@ -67,6 +67,8 @@ public class GnomeFileTypeDetector 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 @@ public class GnomeFileTypeDetector String s = new String(type); return s.equals(GNOME_VFS_MIME_TYPE_UNKNOWN) ? null : s; } - } finally { buffer.release(); }