classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: FileChannelImpl lock() and tryLock() sanity checking


From: Mark Wielaard
Subject: [cp-patches] FYI: FileChannelImpl lock() and tryLock() sanity checking
Date: Tue, 26 Jul 2005 13:59:30 +0200

Hi,

This moves the sanity checking of lock() and tryLock() into a shared
private method checkLock() so that all argument and channel property
checking is done in the same way.

2005-07-26  Mark Wielaard  <address@hidden>

       * gnu/java/nio/channels/FileChannelImpl.java (lockCheck): New method.
       (tryLock): Use lockCheck().
       (lock): Likewise.

This fixes some new mauve tests that I am currently writing.

Committed,

Mark

Index: gnu/java/nio/channels/FileChannelImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/nio/channels/FileChannelImpl.java,v
retrieving revision 1.17
diff -u -r1.17 FileChannelImpl.java
--- gnu/java/nio/channels/FileChannelImpl.java  26 Jul 2005 09:40:21 -0000      
1.17
+++ gnu/java/nio/channels/FileChannelImpl.java  26 Jul 2005 11:57:52 -0000
@@ -443,7 +443,8 @@
     return total;
   }
 
-  public FileLock tryLock (long position, long size, boolean shared)
+  // Shared sanity checks between lock and tryLock methods.
+  private void lockCheck(long position, long size, boolean shared)
     throws IOException
   {
     if (position < 0
@@ -452,16 +453,21 @@
                                          + ", size: " + size);
 
     if (!isOpen ())
-      throw new ClosedChannelException ();
+      throw new ClosedChannelException();
 
-    if (shared && (mode & READ) == 0)
-      throw new NonReadableChannelException ();
-       
-    if (!shared && (mode & WRITE) == 0)
-      throw new NonWritableChannelException ();
+    if (shared && ((mode & READ) == 0))
+      throw new NonReadableChannelException();
        
+    if (!shared && ((mode & WRITE) == 0))
+      throw new NonWritableChannelException();
+  }
+
+  public FileLock tryLock (long position, long size, boolean shared)
+    throws IOException
+  {
+    lockCheck(position, size, shared);
+
     boolean completed = false;
-    
     try
       {
        begin();
@@ -488,16 +494,9 @@
   public FileLock lock (long position, long size, boolean shared)
     throws IOException
   {
-    if (position < 0
-        || size < 0)
-      throw new IllegalArgumentException ("position: " + position
-                                         + ", size: " + size);
-
-    if (!isOpen ())
-      throw new ClosedChannelException ();
+    lockCheck(position, size, shared);
 
     boolean completed = false;
-
     try
       {
        boolean lockable = lock(position, size, shared, true);

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]