classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: Better diagnostics for FileChannelImpl


From: Mark Wielaard
Subject: [cp-patches] FYI: Better diagnostics for FileChannelImpl
Date: Tue, 26 Jul 2005 11:39:25 +0200

Hi,

I had this patch on my disk for a long time. It helps with debugging
file related errors/exceptions a lot.

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

    * gnu/java/nio/channels/FileChannelImpl.java (description):
    New final field.
    (FileChannelImpl): Set description.
    (init): Likewise.
    (toString): New method.
    All methods add parameters when throwing IllegalArgumentException.
    * native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
    (open): Add filename to FileNotFoundException.

No mauve io/nio regressions.
(Although there are a lot of awt failures now because of the strict
assert checking now.)

Committed,

Mark

-- 
Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html

Join the community at http://planet.classpath.org/
Index: gnu/java/nio/channels/FileChannelImpl.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/nio/channels/FileChannelImpl.java,v
retrieving revision 1.16
diff -u -r1.16 FileChannelImpl.java
--- gnu/java/nio/channels/FileChannelImpl.java  25 Jul 2005 13:57:40 -0000      
1.16
+++ gnu/java/nio/channels/FileChannelImpl.java  26 Jul 2005 09:34:42 -0000
@@ -88,9 +88,9 @@
     
     init();
 
-    in  = new FileChannelImpl(0,READ);
-    out = new FileChannelImpl(1,WRITE);
-    err = new FileChannelImpl(2,WRITE);
+    in  = new FileChannelImpl(0, READ);
+    out = new FileChannelImpl(1, WRITE);
+    err = new FileChannelImpl(2, WRITE);
   }
 
   /**
@@ -105,6 +105,8 @@
 
   private int mode;
 
+  final String description;
+
   /* Open a file.  MODE is a combination of the above mode flags. */
   /* This is a static factory method, so that VM implementors can decide
    * substitute subclasses of FileChannelImpl. */
@@ -117,7 +119,8 @@
   private FileChannelImpl(File file, int mode)
     throws FileNotFoundException
   {
-    final String path = file.getPath();
+    String path = file.getPath();
+    description = path;
     fd = open (path, mode);
     this.mode = mode;
 
@@ -134,7 +137,7 @@
              /* ignore it */
          }
 
-       throw new FileNotFoundException(path + " is a directory");
+       throw new FileNotFoundException(description + " is a directory");
       }
   }
 
@@ -151,6 +154,7 @@
   {
     this.fd = fd;
     this.mode = mode;
+    this.description = "descriptor(" + fd + ")";
   }
 
   private native int open (String path, int mode) throws FileNotFoundException;
@@ -191,7 +195,7 @@
     throws IOException
   {
     if (position < 0)
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("position: " + position);
     long oldPosition = implPosition ();
     position (position);
     int result = read(dst);
@@ -242,7 +246,7 @@
     throws IOException
   {
     if (position < 0)
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("position: " + position);
 
     if (!isOpen ())
       throw new ClosedChannelException ();
@@ -300,10 +304,11 @@
          throw new NonWritableChannelException();
       }
     else
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("mode: " + mode);
     
     if (position < 0 || size < 0 || size > Integer.MAX_VALUE)
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("position: " + position
+                                         + ", size: " + size);
     return mapImpl(nmode, position, (int) size);
   }
 
@@ -348,7 +353,8 @@
   {
     if (position < 0
         || count < 0)
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("position: " + position
+                                         + ", count: " + count);
 
     if (!isOpen ())
       throw new ClosedChannelException ();
@@ -411,7 +417,8 @@
   {
     if (position < 0
         || count < 0)
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("position: " + position
+                                         + ", count: " + count);
 
     if (!isOpen ())
       throw new ClosedChannelException ();
@@ -441,7 +448,8 @@
   {
     if (position < 0
         || size < 0)
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("position: " + position
+                                         + ", size: " + size);
 
     if (!isOpen ())
       throw new ClosedChannelException ();
@@ -482,7 +490,8 @@
   {
     if (position < 0
         || size < 0)
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("position: " + position
+                                         + ", size: " + size);
 
     if (!isOpen ())
       throw new ClosedChannelException ();
@@ -516,7 +525,7 @@
     throws IOException
   {
     if (newPosition < 0)
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("newPostition: " + newPosition);
 
     if (!isOpen ())
       throw new ClosedChannelException ();
@@ -531,7 +540,7 @@
     throws IOException
   {
     if (size < 0)
-      throw new IllegalArgumentException ();
+      throw new IllegalArgumentException ("size: " + size);
 
     if (!isOpen ())
       throw new ClosedChannelException ();
@@ -543,5 +552,13 @@
       implTruncate (size);
 
     return this;
+  }
+
+  public String toString()
+  {
+    return (this.getClass()
+           + "[fd=" + fd
+           + ",mode=" + mode + ","
+           + description + "]");
   }
 }
Index: native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c
===================================================================
RCS file: 
/cvsroot/classpath/classpath/native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c,v
retrieving revision 1.20
diff -u -r1.20 gnu_java_nio_channels_FileChannelImpl.c
--- native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 25 Jul 2005 
13:57:40 -0000      1.20
+++ native/jni/java-nio/gnu_java_nio_channels_FileChannelImpl.c 26 Jul 2005 
09:34:42 -0000
@@ -204,17 +204,22 @@
 #endif
 
   TARGET_NATIVE_FILE_OPEN (filename, native_fd, flags, permissions, result);
-  JCL_free_cstring (env, name, filename);
 
   if (result != TARGET_NATIVE_OK)
     {
-      /* We can only throw FileNotFoundException.  */
+      char message[256]; /* Fixed size we don't need to malloc. */
+      char *error_string = TARGET_NATIVE_LAST_ERROR_STRING ();
+
+      snprintf(message, 256, "%s: %s", error_string, filename);
+      /* We are only allowed to throw FileNotFoundException.  */
       JCL_ThrowException (env,
                          "java/io/FileNotFoundException",
-                         TARGET_NATIVE_LAST_ERROR_STRING ());
+                         message);
+      JCL_free_cstring (env, name, filename);
       return TARGET_NATIVE_MATH_INT_INT64_CONST_MINUS_1;
     }
 
+  JCL_free_cstring (env, name, filename);
   return native_fd;
 }
 

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


reply via email to

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