Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8205404

OverlappingFileLockException taking second lock using OS X with ExFAT/MS-DOS

XMLWordPrintable

    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      macOS 10.13.4 using:

      Java version "1.8.0_171"
      Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)


      A DESCRIPTION OF THE PROBLEM :
      Taking a second lock on a ExFAT or MS-DOS (FAT) formatted disk using macOS 10.13.4 always results in a OverlappingFileLockException. If I use DiskUtily and format the drive to Mac OS Extended (Journaled) or Mac OS Extended (Case Sensitive, Journaled) I don't get this issue. If I plug the same drive into a Windows 10 machine I don't get the issue. It's just macOS with ExFAT or MS-DOS (FAT).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Using DiskUtility, format an external drive to ExFAT or MS-DOS (FAT). Update the filePath variable to be the root of your drive and run the attached program.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Program to print:

      filePath: /Volumes/SAMSUNG_T5/a/file.txt
      Got lock: sun.nio.ch.FileLockImpl[0:9223372036854775807 exclusive valid]
      filePath: /Volumes/SAMSUNG_T5/b/file.txt
      Got lock: sun.nio.ch.FileLockImpl[0:9223372036854775807 exclusive valid]

      ACTUAL -
      Unable to take the second lock:

      filePath: /Volumes/SAMSUNG_T5/a/file.txt
      Got lock: sun.nio.ch.FileLockImpl[0:9223372036854775807 exclusive valid]
      filePath: /Volumes/SAMSUNG_T5/b/file.txt
      Exception in thread "main" java.nio.channels.OverlappingFileLockException
      at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
      at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
      at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1108)
      at java.nio.channels.FileChannel.tryLock(FileChannel.java:1155)
      at LockDemo.takeLock(LockDemo.java:35)
      at LockDemo.main(LockDemo.java:25)


      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.nio.channels.FileChannel;
      import java.nio.channels.FileLock;
      import java.nio.file.Files;
      import java.nio.file.Paths;

      public class LockDemo
      {

          public static void main(
              String[] args) throws IOException
          {
              final String filePath = "/Volumes/SAMSUNG_T5";
              final String a = filePath + File.separator + "a";
              final String b = filePath + File.separator + "b";
              
              Files.createDirectories(Paths.get(a));
              Files.createDirectories(Paths.get(b));

              takeLock(a);
              takeLock(b);
          }
          
          private static void takeLock(
              final String pathname) throws IOException
          {
              final String filePath = pathname + File.separator + "file.txt";
              System.out.println("filePath: " + filePath);
              final FileOutputStream os = new FileOutputStream(new File(filePath), true);
              final FileChannel channel = os.getChannel();
              FileLock lock = channel.tryLock();
              System.out.println("Got lock: " + lock);
          }
          
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None.

      FREQUENCY : always


            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: