This is the mail archive of the java-patches@gcc.gnu.org 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]
Other format: [Raw text]

Patch: FYI: fix PR 28178


I'm checking this in on the trunk.

This fixes PR 28178, a small JNI bug.
Test case included.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	PR libgcj/28178:
	* jni.cc (_Jv_JNI_DeleteLocalRef): Ignore null argument.
	(_Jv_JNI_DeleteGlobalRef): Likewise.
	* testsuite/libjava.jni/PR28178.java: New file.
	* testsuite/libjava.jni/PR28178.c: New file.
	* testsuite/libjava.jni/PR28178.out: New file.

Index: jni.cc
===================================================================
--- jni.cc	(revision 115024)
+++ jni.cc	(working copy)
@@ -248,6 +248,12 @@
 {
   // This seems weird but I think it is correct.
   obj = unwrap (obj);
+  
+  // NULL is ok here -- the JNI specification doesn't say so, but this
+  // is a no-op.
+  if (! obj)
+    return;
+
   unmark_for_gc (obj, global_ref_table);
 }
 
@@ -259,6 +265,11 @@
   // This seems weird but I think it is correct.
   obj = unwrap (obj);
 
+  // NULL is ok here -- the JNI specification doesn't say so, but this
+  // is a no-op.
+  if (! obj)
+    return;
+
   for (frame = env->locals; frame != NULL; frame = frame->next)
     {
       for (int i = 0; i < frame->size; ++i)
Index: testsuite/libjava.jni/PR28178.java
===================================================================
--- testsuite/libjava.jni/PR28178.java	(revision 0)
+++ testsuite/libjava.jni/PR28178.java	(revision 0)
@@ -0,0 +1,15 @@
+// Regression test for PR 28178.
+
+public class PR28178
+{
+  static {
+    System.loadLibrary("PR28178");
+  }
+
+  public static native void m();
+
+  public static void main(String[] args)
+  {
+    m();
+  }
+}
Index: testsuite/libjava.jni/PR28178.out
===================================================================
Index: testsuite/libjava.jni/PR28178.c
===================================================================
--- testsuite/libjava.jni/PR28178.c	(revision 0)
+++ testsuite/libjava.jni/PR28178.c	(revision 0)
@@ -0,0 +1,10 @@
+#include <PR28178.h>
+
+void
+Java_PR28178_m (JNIEnv *env, jclass ignore)
+{
+  (*env)->DeleteLocalRef(env, NULL);
+  (*env)->DeleteGlobalRef(env, NULL);
+}
+
+


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