This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: another JNI test


I'm committing another JNI test.

2000-02-16  Tom Tromey  <tromey@cygnus.com>

	* libjava.jni/throwit.java: New file.
	* libjava.jni/throwit.c: New file.
	* libjava.jni/throwit.out: New file.

Tom

Index: libjava.jni/throwit.c
===================================================================
RCS file: throwit.c
diff -N throwit.c
--- /dev/null	Tue May  5 13:32:27 1998
+++ throwit.c	Wed Feb 16 14:35:52 2000
@@ -0,0 +1,25 @@
+#include <stdlib.h>
+#include <throwit.h>
+
+void
+Java_throwit_throwit (JNIEnv *env, jclass klass, jstring name,
+		      jboolean is_new)
+{
+  const char *buf = (*env)->GetStringUTFChars (env, name, NULL);
+  jclass k = (*env)->FindClass (env, buf);
+  (*env)->ReleaseStringUTFChars (env, name, buf);
+
+  if (k == NULL || (*env)->ExceptionCheck (env))
+    return;
+
+  if (is_new)
+    (*env)->ThrowNew (env, k, "the word is zardoz");
+  else
+    {
+      jmethodID id = (*env)->GetMethodID (env, k, "<init>",
+					  "(Ljava.lang.String;)V");
+      jstring z = (*env)->NewStringUTF (env, "zardoz is the word");
+      jobject obj = (*env)->NewObject (env, k, id, z);
+      (*env)->Throw (env, obj);
+    }
+}
Index: libjava.jni/throwit.out
===================================================================
RCS file: throwit.out
diff -N throwit.out
--- /dev/null	Tue May  5 13:32:27 1998
+++ throwit.out	Wed Feb 16 14:35:52 2000
@@ -0,0 +1,4 @@
+class java.lang.UnknownError
+the word is zardoz
+class java.lang.Throwable
+zardoz is the word
Index: libjava.jni/throwit.java
===================================================================
RCS file: throwit.java
diff -N throwit.java
--- /dev/null	Tue May  5 13:32:27 1998
+++ throwit.java	Wed Feb 16 14:35:52 2000
@@ -0,0 +1,33 @@
+// Test to see if throw works.
+
+public class throwit
+{
+  static
+  {
+    System.loadLibrary ("throwit");
+  }
+
+  public static native void throwit (String name, boolean is_new);
+
+  public static void main (String[] args)
+  {
+    try
+      {
+	throwit ("java/lang/UnknownError", false);
+      }
+    catch (Throwable x)
+      {
+	System.out.println (x.getClass ());
+	System.out.println (x.getMessage ());
+      }
+    try
+      {
+	throwit ("java/lang/Throwable", true);
+      }
+    catch (Throwable x)
+      {
+	System.out.println (x.getClass ());
+	System.out.println (x.getMessage ());
+      }
+  }
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]