@Override public synchronized FileLock tryLock(long position, long size, boolean shared) throws IOException { if (shared) { if (!data.lockShared()) { return null; } } else { if (!data.lockExclusive()) { return null; } } // cast to FileChannel to avoid JDK 1.7 ambiguity FileLock lock = new FileLock((FileChannel) null, position, size, shared) { @Override public boolean isValid() { return true; } @Override public void release() throws IOException { data.unlock(); } }; return lock; }