sam18
sam18

Reputation: 641

How to handle "JNI WARNING : 0x44f81e80 is not a valid JNI reference"

I am facing crash with

JNI WARNING : 0x44f81e80 is not a valid JNI reference, in Ldalvik/system/NativeStart;. run()v (GetObjectClass)

I found some post saying use NewWeakGlobalRef instead NewGlobalRef. But I am looking for validation in my code. All I want to know is is there any JNI api using which I can check whether given jobject is valid JNI reference or not? Something like unsigned

char isValid = (env)IsValidJNIRef(myjobject);

Using that isValid's value I can put some condition to handle system.

Thanks.

Upvotes: 2

Views: 950

Answers (1)

GooseSerbus
GooseSerbus

Reputation: 1260

You can check the ref type of a jobject referred to by the obj argument using:

jobjectRefType GetObjectRefType(JNIEnv* env, jobject obj);

Which returns one of the following enumerated values defined as a jobjectRefType:

JNIInvalidRefType = 0,
JNILocalRefType = 1,
JNIGlobalRefType = 2,
JNIWeakGlobalRefType = 3

Note that you can't use this on deleted refs - it is not specified what value the GetObjectRefType will return for a deleted ref.

See: http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#objreftype

Upvotes: 1

Related Questions