| 720 | } |
| 721 | |
| 722 | jclass JEnv::FindClass(const string &className) { |
| 723 | jclass global_class = CheckForClassInCache(className); |
| 724 | |
| 725 | if (global_class == nullptr) { |
| 726 | auto classIsMissing = CheckForClassMissingCache(className); |
| 727 | // class is missing. Set the same JNI error we had when we tried to find it the first time |
| 728 | if (classIsMissing != nullptr) { |
| 729 | m_env->Throw(classIsMissing); |
| 730 | return nullptr; |
| 731 | } |
| 732 | jclass tmp = m_env->FindClass(className.c_str()); |
| 733 | |
| 734 | if (m_env->ExceptionCheck() == JNI_TRUE) { |
| 735 | m_env->ExceptionClear(); |
| 736 | string cannonicalClassName = Util::ConvertFromJniToCanonicalName(className); |
| 737 | jstring s = m_env->NewStringUTF(cannonicalClassName.c_str()); |
| 738 | tmp = static_cast<jclass>(m_env->CallStaticObjectMethod(RUNTIME_CLASS, |
| 739 | GET_CACHED_CLASS_METHOD_ID, s)); |
| 740 | |
| 741 | m_env->DeleteLocalRef(s); |
| 742 | // we failed our static class check |
| 743 | // if we continue, we will crash (C++ level) |
| 744 | // so just return null and let the runtime deal with the NativeScriptException |
| 745 | if (m_env->ExceptionCheck() == JNI_TRUE) { |
| 746 | auto tmpException = m_env->ExceptionOccurred(); |
| 747 | m_env->ExceptionClear(); |
| 748 | m_env->Throw(InsertClassIntoMissingCache(className, tmpException)); |
| 749 | return nullptr; |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | global_class = InsertClassIntoCache(className, tmp); |
| 754 | } |
| 755 | |
| 756 | return global_class; |
| 757 | } |
| 758 | |
| 759 | jclass JEnv::CheckForClassInCache(const string &className) { |
| 760 | jclass global_class = nullptr; |