summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/kernel/qjni.cpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/corelib/kernel/qjni.cpp b/src/corelib/kernel/qjni.cpp
index 437205bf92..aa9b196e62 100644
--- a/src/corelib/kernel/qjni.cpp
+++ b/src/corelib/kernel/qjni.cpp
@@ -67,6 +67,19 @@ static QString qt_convertJString(jstring string)
return res;
}
+static inline bool exceptionCheckAndClear(JNIEnv *env)
+{
+ if (Q_UNLIKELY(env->ExceptionCheck())) {
+#ifdef QT_DEBUG
+ env->ExceptionDescribe();
+#endif // QT_DEBUG
+ env->ExceptionClear();
+ return true;
+ }
+
+ return false;
+}
+
typedef QHash<QString, jclass> JClassHash;
Q_GLOBAL_STATIC(JClassHash, cachedClasses)
@@ -85,14 +98,8 @@ static jclass getCachedClass(JNIEnv *env, const char *className)
QJNIObjectPrivate classObject = classLoader.callObjectMethod("loadClass",
"(Ljava/lang/String;)Ljava/lang/Class;",
stringName.object());
- if (env->ExceptionCheck()) {
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif // QT_DEBUG
- env->ExceptionClear();
- }
- if (classObject.isValid())
+ if (!exceptionCheckAndClear(env) && classObject.isValid())
clazz = static_cast<jclass>(env->NewGlobalRef(classObject.object()));
cachedClasses->insert(key, clazz);
@@ -121,13 +128,8 @@ static jmethodID getCachedMethodID(JNIEnv *env,
else
id = env->GetMethodID(clazz, name, sig);
- if (env->ExceptionCheck()) {
+ if (exceptionCheckAndClear(env))
id = 0;
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif // QT_DEBUG
- env->ExceptionClear();
- }
cachedMethodID->insert(key, id);
} else {
@@ -154,13 +156,8 @@ static jfieldID getCachedFieldID(JNIEnv *env,
else
id = env->GetFieldID(clazz, name, sig);
- if (env->ExceptionCheck()) {
+ if (exceptionCheckAndClear(env))
id = 0;
-#ifdef QT_DEBUG
- env->ExceptionDescribe();
-#endif // QT_DEBUG
- env->ExceptionClear();
- }
cachedFieldID->insert(key, id);
} else {