summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@digia.com>2014-06-12 14:49:37 +0200
committerChristian Stromme <christian.stromme@digia.com>2014-07-07 12:00:57 +0200
commitf17494e9b829f079bf632eed7757c1a30f360b68 (patch)
treeb8de00979b7a32614a3afe58d7ff023714d43761 /src/corelib
parenta2948e1387ce1fb6d624d7387aa7769a5c5a4dad (diff)
Android: Refactor exception checking in qjni.
In places where we call java/jni functions that can throw exceptions, we check and clear the exception, if necessary. This change moves the "checking" code into a single (private) function. Change-Id: Ic3de2be51305972b096e1ed0a477e341eb5d9404 Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
Diffstat (limited to 'src/corelib')
-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 {