classpath
[Top][All Lists]
Advanced

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

Re: JNI assertion failure


From: Archie Cobbs
Subject: Re: JNI assertion failure
Date: Sat, 23 Jul 2005 14:37:34 -0500
User-agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.3) Gecko/20041129

Archie Cobbs wrote:
With Classpath 0.16, trying to run a very simple Swing demo under JCVM,
I get a JNI assertion failure in a call to GetIntField(), because the object
type and the fieldID are not compatible:

gnu/java/awt/peer/gtk/address@hidden not instance of gnu/java/awt/peer/gtk/GtkGenericPeer

Here is the relevant stack trace snippet:

#7 0x29f862d7 in Java_gnu_java_awt_peer_gtk_GdkGraphics_initState__Lgnu_java_awt_peer_gtk_GtkComponentPeer_2 (env=0x107ed6a0, obj=0x29795698, peer=0x2979569c)
    at gnu_java_awt_peer_gtk_GdkGraphics.c:154

Hmm, no response.. can anyone else confirm this problem??

It looks like this code is completely broken, because
it's trying to save a pointer in a field that doesn't
exist. Line 154 of gnu_java_awt_peer_gtk_GdkGraphics.c says:

  NSA_SET_PTR (env, obj, g)

but "obj" is a gnu/java/awt/peer/gtk/GdkGraphics object, not
a gnu/java/awt/peer/gtk/GtkGenericPeer object, the class that
contains the "native_state" field.

Since nobody seems to be listening, I'm going to check in the
attached patch. This will cause all programs that use the GTK
peer to crash with an assertion failure. Sorry! The code
is broken but I don't know how to fix it. At least now we get
an assertion failure instead of random memory corruption.

You have been warned :-)

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com
Index: native/jni/classpath/native_state.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/classpath/native_state.c,v
retrieving revision 1.11
diff -u -r1.11 native_state.c
--- native/jni/classpath/native_state.c 14 Jul 2005 22:07:02 -0000      1.11
+++ native/jni/classpath/native_state.c 23 Jul 2005 19:30:28 -0000
@@ -36,6 +36,7 @@
 exception statement from your version. */
 
 #include <stdlib.h>
+#include <assert.h>
 #include <jni.h>
 #include "native_state.h"
 
@@ -214,6 +215,10 @@
 cp_gtk_set_state (JNIEnv * env, jobject obj, struct state_table *table, void 
*state)
 {
   jint obj_id;
+
+  assert ((*env)->IsAssignableFrom(env,
+    (*env)->GetObjectClass(env, obj), table->clazz));
+
   obj_id = (*env)->GetIntField (env, obj, table->hash);
 
   if ((*env)->ExceptionOccurred (env) != NULL)
@@ -227,6 +232,10 @@
 cp_gtk_get_state (JNIEnv * env, jobject obj, struct state_table *table)
 {
   jint obj_id;
+
+  assert ((*env)->IsAssignableFrom(env,
+    (*env)->GetObjectClass(env, obj), table->clazz));
+
   obj_id = (*env)->GetIntField (env, obj, table->hash);
 
   if ((*env)->ExceptionOccurred (env) != NULL)
@@ -239,6 +248,10 @@
 cp_gtk_remove_state_slot (JNIEnv * env, jobject obj, struct state_table *table)
 {
   jint obj_id;
+
+  assert ((*env)->IsAssignableFrom(env,
+    (*env)->GetObjectClass(env, obj), table->clazz));
+
   obj_id = (*env)->GetIntField (env, obj, table->hash);
 
   if ((*env)->ExceptionOccurred (env) != NULL)

reply via email to

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