I am new to SWIG, so I was hoping you could help me with a problem. We are using SWIG 1.3.40 (with almost no hope of upgrading) and Java 6.


I haven’t been able to recreate the problem so far. It seems to be pretty rare and also seems to happen very soon after the program starts. I do have two logs where this exception has occurred in my program:

“Exception in thread “Timer-41” java.lang.NullPointerException: null upcall object”. When this exception happens, some nasty effects soon follow. So I would like to diagnose and fix the problem.


I tracked the exception down to a generated SWIG director. We are using 3 different directors, so I am not sure which is causing the exception, but they all have the same generated code:

      void SwigDirector_something::processCallback(Someobject &t) {

  JNIEnvWrapper swigjnienv(this);

  JNIEnv * jenv = swigjnienv.getJNIEnv();

  jobject swigjobj = (jobject) NULL;

  jlong jt = 0;


  if (!swig_override[0]) {




  swigjobj = swig_get_self(jenv);

  if (swigjobj && jenv->IsSameObject(swigjobj, NULL) == JNI_FALSE) {


  } else {

    SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null upcall object");


  if (swigjobj) jenv->DeleteLocalRef(swigjobj);



So, “(swigjobj && jenv->IsSameObject(swigjobj, NULL) == JNI_FALSE)” must be false and the else gets called, throwing the exception. But I have no idea why this would happen.


Any help you can give me to figure out why this is happening or how to fix it would be greatly appreciated.



Chris Fry