JNI and class references

Marcus G. Daniels mgd@swarm.org
Sun Mar 25 16:52:00 GMT 2001


In jni.cc, I see there's a template for jobject wrap_value, but not
one for jclass.  My experience with JNI is that a jclass returned
from a call like GetObjectClass is also a local reference.

Is it not appropriate to also have a wrap_value for jclass returns?
Specifically, like this:

template<>
static jclass
wrap_value (JNIEnv *env, jclass value)
{
  return value == NULL ? value : (jclass) _Jv_JNI_NewLocalRef (env, (jobject) value);
}

(The motivation being that code that expects that jclasses will be local
refs will be calling DeleteLocalRef in some circumstances, which will
crash the runtime if there isn't one.)



More information about the Java mailing list