### Eclipse Workspace Patch 1.0
#P classpath
Index: native/jni/classpath/jcl.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/classpath/jcl.c,v
retrieving revision 1.27
diff -u -r1.27 jcl.c
--- native/jni/classpath/jcl.c	17 Oct 2006 14:14:16 -0000	1.27
+++ native/jni/classpath/jcl.c	3 Feb 2007 01:59:19 -0000
@@ -55,6 +55,8 @@
 static jfieldID rawData_fid = NULL;
 static jmethodID rawData_mid = NULL;
 
+static jthrowable OOM_obj = NULL;
+
 /*
  * JNI OnLoad constructor.
  */
@@ -95,6 +97,17 @@
 #endif /* SIZEOF_VOID_P == 4 */
 #endif /* SIZEOF_VOID_P == 8 */
 
+  {
+    jclass oom_class;
+    jmethodID oom_ctor;
+    oom_class = (*env)->FindClass (env, "java/lang/OutOfMemoryError");
+    assert(oom_class != NULL);
+    oom_ctor = (*env)->GetMethodID (env, oom_class, "<init>", "V()");
+    assert(oom_ctor != NULL);
+    OOM_obj = (*env)->NewObject (env, oom_class, oom_ctor);
+    (*env)->NewGlobalRef (env, OOM_obj);
+  }
+
   return JNI_VERSION_1_4;
 }
 
@@ -132,18 +145,90 @@
        * sprintf(errstr,"JCL: Failed to throw exception %s with message %s: could not find exception class.", className, errMsg); 
        */
       (*env)->ThrowNew (env, errExcClass, className);
+      return;
     }
   (*env)->ThrowNew (env, excClass, errMsg);
 }
 
+/*
+ * Similar to JCL_ThrowException, but uses the void constructor of
+ * the exception class.
+ *
+ * This method name is inconvenient because you should try to
+ * think up an exception message, and use this only for classes
+ * that don't have String constructors.
+ */
+JNIEXPORT void JNICALL
+JCL_ThrowExceptionNoMessage (JNIEnv *env, const char *className)
+{
+  jclass excClass;
+  jmethodID ctor;
+  jthrowable toThrow;
+
+  if ((*env)->ExceptionOccurred (env))
+    {
+      (*env)->ExceptionClear (env);
+    }
+
+  excClass = (*env)->FindClass (env, className);
+  if (excClass == NULL)
+    {
+      jclass errExcClass;
+      errExcClass =
+	(*env)->FindClass (env, "java/lang/ClassNotFoundException");
+      if (errExcClass == NULL)
+	{
+	  errExcClass = (*env)->FindClass (env, "java/lang/InternalError");
+	  if (errExcClass == NULL)
+	    {
+	      fprintf (stderr, "JCL: Utterly failed to throw exeption ");
+	      fprintf (stderr, "%s", className);
+	      return;
+	    }
+	}
+      (*env)->ThrowNew (env, errExcClass, className);
+      return;
+    }
+
+  ctor = (*env)->GetMethodID (env, excClass, "<init>", "V()");
+  if (ctor == NULL)
+    {
+      const char *errMsg = "exception class does not have void constructor";
+      jclass errExcClass =
+        (*env)->FindClass (env, "java/lang/NoSuchMethodError");
+      if (errExcClass == NULL)
+        {
+          errMsg = "exception class does not have void constructor, and could not load NoSuchMethodError class";
+	  errExcClass = (*env)->FindClass (env, "java/lang/InternalError");
+	  if (errExcClass == NULL)
+	    {
+	      fprintf (stderr, "JCL: Utterly failed to throw exeption ");
+	      fprintf (stderr, "%s", className);
+	      return;
+	    }
+        }
+      (*env)->ThrowNew (env, errExcClass, errMsg);
+      return;
+    }
+
+  toThrow = (*env)->NewObject (env, excClass, ctor);
+  if (toThrow == NULL)
+    {
+      /* Sigh. */
+      (*env)->Throw (env, OOM_obj);
+      return;
+    }
+
+  (*env)->Throw (env, toThrow);
+}
+
 JNIEXPORT void *JNICALL
 JCL_malloc (JNIEnv * env, size_t size)
 {
   void *mem = malloc (size);
   if (mem == NULL)
     {
-      JCL_ThrowException (env, "java/lang/OutOfMemoryError",
-			  "malloc() failed.");
+      (*env)->Throw (env, OOM_obj);
       return NULL;
     }
   return mem;
@@ -155,8 +240,7 @@
   ptr = realloc (ptr, size);
   if (ptr == 0)
     {
-      JCL_ThrowException (env, "java/lang/OutOfMemoryError",
-			  "malloc() failed.");
+      (*env)->Throw (env, OOM_obj);
       return NULL;
     }
   return (ptr);
Index: native/jni/classpath/jcl.h
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/classpath/jcl.h,v
retrieving revision 1.18
diff -u -r1.18 jcl.h
--- native/jni/classpath/jcl.h	30 May 2006 11:30:02 -0000	1.18
+++ native/jni/classpath/jcl.h	3 Feb 2007 01:59:19 -0000
@@ -41,6 +41,7 @@
 #include <stddef.h>
 #include <jni.h>
 #include <config.h>
+#include <assert.h>
 
 #if SIZEOF_VOID_P == 4
 typedef jint jpointer;
@@ -58,6 +59,8 @@
 JNIEXPORT void JNICALL JCL_ThrowException (JNIEnv * env,
 					   const char *className,
 					   const char *errMsg);
+JNIEXPORT void JNICALL JCL_ThrowExceptionNoMessage (JNIEnv *env,
+                                                    const char *className);
 JNIEXPORT void *JNICALL JCL_malloc (JNIEnv * env, size_t size);
 JNIEXPORT void *JNICALL JCL_realloc (JNIEnv * env, void *ptr, size_t size);
 JNIEXPORT void JNICALL JCL_free (JNIEnv * env, void *p);
Index: native/jni/java-nio/gnu_java_nio_VMChannel.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/java-nio/gnu_java_nio_VMChannel.c,v
retrieving revision 1.15
diff -u -r1.15 gnu_java_nio_VMChannel.c
--- native/jni/java-nio/gnu_java_nio_VMChannel.c	28 Jan 2007 13:32:33 -0000	1.15
+++ native/jni/java-nio/gnu_java_nio_VMChannel.c	3 Feb 2007 01:59:19 -0000
@@ -449,8 +449,7 @@
       else if (errno == EBADF) /* Bad fd */
         {
           JCL_release_buffer(env, &buf, bbuf, JNI_ABORT);
-          JCL_ThrowException (env, NON_READABLE_CHANNEL_EXCEPTION, 
-                              strerror(errno));
+          JCL_ThrowExceptionNoMessage (env, NON_READABLE_CHANNEL_EXCEPTION);
           return -1;
         }
       else if (EINTR == errno) /* read interrupted */
@@ -624,8 +623,7 @@
       else if (errno == EBADF) /* Bad fd */
         {
           JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, bytes_read);
-          JCL_ThrowException (env, NON_READABLE_CHANNEL_EXCEPTION, 
-                              strerror(errno));
+          JCL_ThrowExceptionNoMessage (env, NON_READABLE_CHANNEL_EXCEPTION);
           return -1;
         } 
       else
@@ -715,8 +713,7 @@
         {
           JCL_cleanup_buffers(env, bi_list, vec_len, bbufs, offset, 
                               bytes_written);
-          JCL_ThrowException (env, NON_WRITABLE_CHANNEL_EXCEPTION, 
-                              strerror(errno));
+          JCL_ThrowExceptionNoMessage (env, NON_WRITABLE_CHANNEL_EXCEPTION); 
           return -1;
         } 
       else
