changeset 713:e3022f78da3b

FileLock#getChannel creates confusion with pre-existing channel method.
author alanb
date Tue, 14 Oct 2008 10:33:31 +0100
parents 251f70664db0
children 49e645ae6ee9
files src/share/classes/java/nio/channels/FileLock.java src/share/classes/sun/nio/ch/FileLockImpl.java test/java/nio/channels/AsynchronousFileChannel/Basic.java
diffstat 3 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/nio/channels/FileLock.java	Tue Oct 14 10:07:09 2008 +0100
+++ b/src/share/classes/java/nio/channels/FileLock.java	Tue Oct 14 10:33:31 2008 +0100
@@ -200,25 +200,27 @@
 
     /**
      * {@note revised}
-     * Returns the file channel upon whose file this lock is held, or
-     * <tt>null</tt> if this lock was obtained by a channel other than a file
-     * channel.
+     * Returns the file channel upon whose file this lock was acquired.
      *
-     * @return  The file channel
+     * <p> This method has been superseded by the {@link #acquiredBy acquiredBy}
+     * method.
+     *
+     * @return  The file channel, or {@code null} if the file lock was not
+     *          acquired by a file channel.
      */
     public final FileChannel channel() {
         return (channel instanceof FileChannel) ? (FileChannel)channel : null;
     }
 
-
     /**
      * {@note new}
-     * Returns the channel upon whose file this lock is held.
-     * @return  The channel
+     * Returns the channel upon whose file this lock was acquired.
+     *
+     * @return  The channel upon whose file this lock was acquired.
      *
      * @since 1.7
      */
-    public Channel getChannel() {
+    public Channel acquiredBy() {
         return channel;
     }
 
--- a/src/share/classes/sun/nio/ch/FileLockImpl.java	Tue Oct 14 10:07:09 2008 +0100
+++ b/src/share/classes/sun/nio/ch/FileLockImpl.java	Tue Oct 14 10:33:31 2008 +0100
@@ -54,14 +54,15 @@
     }
 
     public synchronized void release() throws IOException {
-        Channel ch = getChannel();
+        Channel ch = acquiredBy();
         if (!ch.isOpen())
             throw new ClosedChannelException();
         if (valid) {
             if (ch instanceof FileChannelImpl)
                 ((FileChannelImpl)ch).release(this);
-            if (ch instanceof AsynchronousFileChannelImpl)
+            else if (ch instanceof AsynchronousFileChannelImpl)
                 ((AsynchronousFileChannelImpl)ch).release(this);
+            else throw new AssertionError();
             valid = false;
         }
     }
--- a/test/java/nio/channels/AsynchronousFileChannel/Basic.java	Tue Oct 14 10:07:09 2008 +0100
+++ b/test/java/nio/channels/AsynchronousFileChannel/Basic.java	Tue Oct 14 10:33:31 2008 +0100
@@ -175,8 +175,8 @@
         } catch (InterruptedException x) {
             throw new RuntimeException("Should not be interrupted");
         }
-        if (!fl.getChannel().equals(ch))
-            throw new RuntimeException("FileLock#getChannel returned incorrect channel");
+        if (!fl.acquiredBy().equals(ch))
+            throw new RuntimeException("FileLock#acquiredBy returned incorrect channel");
         try {
             ch.tryLock();
             throw new RuntimeException("OverlappingFileLockException expected");