src/java.base/unix/classes/sun/nio/fs/GnomeFileTypeDetector.java

Print this page
rev 12529 : 8080115: (fs) Crash in libgio when calling Files.probeContentType(path) from parallel threads
Summary: Make GnomeFileTypeDetector.probeGio() synchronized and add a regression test based on the test source included in JDK-8080115.
Reviewed-by: XXX


  50         if (!gioAvailable)
  51             return null;
  52         if (!(obj instanceof UnixPath))
  53             return null;
  54 
  55         UnixPath path = (UnixPath)obj;
  56         NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls());
  57         try {
  58             // GIO may access file so need permission check
  59             path.checkRead();
  60             byte[] type = probeGio(buffer.address());
  61             return (type == null) ? null : Util.toString(type);
  62         } finally {
  63             buffer.release();
  64         }
  65 
  66     }
  67 
  68     // GIO
  69     private static native boolean initializeGio();
  70     private static native byte[] probeGio(long pathAddress);
  71 
  72     static {
  73         AccessController.doPrivileged(new PrivilegedAction<>() {
  74             public Void run() {
  75                 System.loadLibrary("nio");
  76                 return null;
  77         }});
  78     }
  79 }


  50         if (!gioAvailable)
  51             return null;
  52         if (!(obj instanceof UnixPath))
  53             return null;
  54 
  55         UnixPath path = (UnixPath)obj;
  56         NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls());
  57         try {
  58             // GIO may access file so need permission check
  59             path.checkRead();
  60             byte[] type = probeGio(buffer.address());
  61             return (type == null) ? null : Util.toString(type);
  62         } finally {
  63             buffer.release();
  64         }
  65 
  66     }
  67 
  68     // GIO
  69     private static native boolean initializeGio();
  70     private static synchronized native byte[] probeGio(long pathAddress);
  71 
  72     static {
  73         AccessController.doPrivileged(new PrivilegedAction<>() {
  74             public Void run() {
  75                 System.loadLibrary("nio");
  76                 return null;
  77         }});
  78     }
  79 }