Hi Alex,


Your question got me to look deeper into how the director object is being created. I thought it was being created correctly in a way that no other thread could call the object before it was done initializing. After looking at the code more, it turns out I was wrong.


The director class is created in two steps from the generated java code.

1.      Create an instance of the director class by calling the JNI constructor

2.      Call director_connect on the instance

Unfortunately, my director classes all extend (derive) from another class Foo. Foo in its constructor method adds “this” to a list of callbacks that can be used. Depending on the timing, my director can be created by step 1, added to the list of callbacks and called as a callback (in another thread), before step 2 takes place. This causes the “null upcall exception”.


Thanks for your help,

Chris Fry






From: Alexander Borovikov [mailto:dsbalbor@gmail.com]
Sent: Saturday, July 05, 2014 12:55 PM
To: Fry, Chris (EXP)
Subject: EXTERNAL: Re: [Swig-user] NullPointerException: null upcall exception


Hi Chris,


not sure, but I could have had a similar case. Just to clarify: I guess you have you own class OwnClass derived from a wrapper. Then you address and object of this class, call a method and get into director. How you create the OwnClass object?





2014-07-02 23:10 GMT+04:00 Fry, Chris (EXP) <chris.fry@lmco.com>:



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


Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
Swig-user mailing list