Make JNI lib more robust by validating handle objects