Fix some JNI bugs