title: OverlappingFileLockException when trying to lock a file channel
body: <p>Premises:</p>
  
  <ul>
  <li>I get OverlappingFileLockException <strong>every</strong> time i try to lock a file (this applies to all files)</li>
  <li>I have a freshly booted machine</li>
  <li>Tested on both Windows/Linux through Eclipse, java v1.6</li>
  <li>Just one instance of Eclipse is running with this single program</li>
  <li>Just one thread running in this program (event dispatching thread)</li>
  <li>I have tried to lock files that i have never touched before</li>
  <li>Same problem using both lock() and trylock()</li>
  <li>Changing from FileOutputStream() to RandomAccessFile() yields same result</li>
  </ul>
  
  <p>I am trying to lock a file in a static function, the function returns a composed object that contains the channel and the lock so another function, unlockFile(FileLocking fl) can be used to close then channel and release the lock. The composed object class looks like this:
  `</p>
  
  <pre><code>   public class FileLocking {
      public FileChannel channel;
      public FileLock lock;
  
      public FileLocking(FileChannel f, FileLock l) {
          channel = f;
          lock = l;
      }
  </code></pre>
  
  <p>The function that locks the file looks like this:</p>
  
  <pre><code>public static synchronized FileLocking lockFile(String fileName) {
  FileLocking result = null;
  FileChannel channel = null;
  try {
      channel = new FileOutputStream(fileName).getChannel();
      FileLock lock = channel.lock();
      lock = channel.tryLock();
      result = new FileLocking(channel, lock);
  } catch (Exception e) {
      Log(ERR, "Exception when locking " + e.getMessage());
      e.printStackTrace();
  } finally {
      try {
          channel.close();
      } catch (IOException e) {
          Log(ERR, "IOE: " + e.getMessage());
          e.printStackTrace();
      }
  }
  return result;
  </code></pre>
  
  <p>}</p>
  
  <p>Currently, i get the following error:</p>
  
  <pre><code>[ERR]: (pid:13) Exception when locking null
  java.nio.channels.OverlappingFileLockException
  at sun.nio.ch.FileChannelImpl$SharedFileLockTable.checkList(Unknown Source)
  at sun.nio.ch.FileChannelImpl$SharedFileLockTable.add(Unknown Source)
  at sun.nio.ch.FileChannelImpl.tryLock(Unknown Source)
  at java.nio.channels.FileChannel.tryLock(Unknown Source)
  at com.xxx.utils.FileLocking.lockFile(FileLocking.java:29)`
  </code></pre>
  
  <p>Explanations and/or coding techniques are highly appreciated.</p>