java.io.IOException: Operation not supported

JDK Bug System | Hendrik Schreiber | 2 months ago
  1. 0

    Samba Share + Grade = Java IO Exception

    Stack Overflow | 1 year ago | christian667
    java.io.IOException: Operation not supported
  2. 0

    When trying to lock a file that is on a SMB or an AFP network filesystem, FileChannel.tryLock() throws an IOException with the message "Operation not supported" . The reason seems to be that the JRE uses the call fcntl to try to lock files on these network shares. On OS X fcntl does not support locking files on AFP or SMB (I believe NFS works alright, but am not certain). A possible alternative is perhaps the call flock for AFP and SMB. More general information can be found on http://www.briandwells.com/main/Blog/Entries/2006/10/5_Subversion,_Mac_OS_X,_and_SMB.html To test the problem, mount an SMB or AFP share on a OS X machine. Then run this code with one of the mounted files as argument: import java.io.*; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; public class FileLockTest { public static void main(String[] args) throws Exception { RandomAccessFile file = null; FileLock fileLock = null; try { file = new RandomAccessFile(args[0], "rw"); FileChannel fileChannel = file.getChannel(); fileLock = fileChannel.tryLock(); if (fileLock != null){ System.out.println("File is locked"); } } finally{ if (fileLock != null){ fileLock.release(); } } } } When working properly, you should see the text "File is locked". When failing, you see something like: Exception in thread "main" java.io.IOException: Operation not supported at sun.nio.ch.FileDispatcherImpl.lock0(Native Method) at sun.nio.ch.FileDispatcherImpl.lock(FileDispatcherImpl.java:90) at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1114) at java.nio.channels.FileChannel.tryLock(FileChannel.java:1155) at FileLockTest.main(FileLockTest.java:15) Please note that the thrown exception is not very helpful, because it is a plain IOException with some message. As a programmer, I'd like to distinguish between a real failure or an unsupported operation. Even if for some reason proper locking cannot be implemented, please implement a specific exception that is thrown in case a file cannot be locked, because the mechanism isn't properly implemented or supported by the OS. Something like FileLockUnsupportedException (subclass of IOException) with a proper reason that perhaps contains the filesystem type.

    JDK Bug System | 2 months ago | Hendrik Schreiber
    java.io.IOException: Operation not supported
  3. 0

    Bug ID: JDK-4532474 (fs) FileChannel.lock()/tryLock() methods unusable

    java.com | 8 months ago
    java.io.IOException: The parameter is incorrect
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Bug 46548 – Eclipse crashes on launch when workspace not on local drive

    eclipse.org | 12 months ago
    java.io.IOException: Operation not supported
  6. 0

    Eclipse crashes on launch when workspace not on local drive

    Eclipse Bugzilla | 1 decade ago | anewby
    java.io.IOException: Operation not supported

  1. ivotje50 41 times, last 3 months ago
  2. Avinash8989 7 times, last 4 months ago
  3. ank_07 7 times, last 4 months ago
  4. Pawan 2 times, last 5 months ago
  5. brunosatriani 6 times, last 5 months ago
8 more registered users
3 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.io.IOException

    Operation not supported

    at sun.nio.ch.FileDispatcherImpl.lock0()
  2. Java RT
    FileChannel.tryLock
    1. sun.nio.ch.FileDispatcherImpl.lock0(Native Method)
    2. sun.nio.ch.FileDispatcherImpl.lock(FileDispatcherImpl.java:90)
    3. sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1114)
    4. java.nio.channels.FileChannel.tryLock(FileChannel.java:1155)
    4 frames
  3. Unknown
    FileLockTest.main
    1. FileLockTest.main(FileLockTest.java:15)
    1 frame