According to the spec, FileChannel.tryLock() should return null in the event that it cannot acquire a lock. libgcj's implementation does not currently do this and returns a FileLock object even though the lock has not been acquired. See attached test case.
Created attachment 8810 [details] test case part 1 Run this part first.
Created attachment 8811 [details] test case part 1 Run this file and leave it running while you try to run the second attachment (forthcoming).
Created attachment 8812 [details] second part to the test case Run this while TestLocking2 is running.
Created attachment 8813 [details] patch
This patch looks good to me. Could you write a ChangeLog entry for it?
(In reply to comment #5) > This patch looks good to me. > Could you write a ChangeLog entry for it? He did in <http://gcc.gnu.org/ml/java-patches/2005-q2/msg00371.html> Confirmed,
There is already a ChangeLog entry with the patch
Subject: Bug 21372 CVSROOT: /cvs/gcc Module name: gcc Changes by: tromey@gcc.gnu.org 2005-05-03 22:38:17 Modified files: libjava : ChangeLog libjava/java/nio/channels: FileLock.java libjava/gnu/java/nio/channels: FileChannelImpl.java Log message: 2005-05-03 Andrew Overholt <overholt@redhat.com> PR libgcj/21372: * gnu/java/nio/channels/FileChannelImpl.java: Return null if lock could not be acquired. * java/nio/channels/FileLock.java (toString): Re-implement to be in line with other implementations. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3584&r2=1.3585 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/nio/channels/FileLock.java.diff?cvsroot=gcc&r1=1.4&r2=1.5 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/gnu/java/nio/channels/FileChannelImpl.java.diff?cvsroot=gcc&r1=1.10&r2=1.11
Subject: Bug 21372 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: tromey@gcc.gnu.org 2005-05-03 22:47:13 Modified files: libjava : ChangeLog libjava/java/nio/channels: FileLock.java libjava/gnu/java/nio/channels: FileChannelImpl.java Log message: 2005-05-03 Andrew Overholt <overholt@redhat.com> PR libgcj/21372: * gnu/java/nio/channels/FileChannelImpl.java: Return null if lock could not be acquired. * java/nio/channels/FileLock.java (toString): Re-implement to be in line with other implementations. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.3391.2.56&r2=1.3391.2.57 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/nio/channels/FileLock.java.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4&r2=1.4.40.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/gnu/java/nio/channels/FileChannelImpl.java.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.7.4.2&r2=1.7.4.3
I checked in the fix to the trunk, the 4.0 branch, and Classpath. Thanks for the clear test case and patch.