Java threads created from JNI code in a non-java thread have null ContextClassloader unless the creator explicitly sets it.
Also in such context Thread.currentThread() returns null.
This can be fixed by setting "ClassLoader cl = ClassLoader.getSystemClassLoader()" instade of "Thread.currentThread().setContextClassLoader(cl)"