Rename QJniEnvironment exceptionCheckAndClear to checkAndClearExceptions

Address feedback from header view.

Task-number: QTBUG-90211
Pick-to: 6.1
Change-Id: Iad2b609598b16f66fd6ab09484fe6e6899981263
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Assam Boudjelthia 2021-03-26 10:48:49 +02:00 committed by Volker Hilsheimer
parent 35dd643b07
commit b9f27335e7
6 changed files with 55 additions and 55 deletions

View File

@ -128,11 +128,11 @@ QJniEnvironment::QJniEnvironment()
\fn QJniEnvironment::~QJniEnvironment()
Detaches the current thread from the Java VM and destroys the QJniEnvironment object.
This will clear any pending exception by calling exceptionCheckAndClear().
This will clear any pending exception by calling checkAndClearExceptions().
*/
QJniEnvironment::~QJniEnvironment()
{
exceptionCheckAndClear();
checkAndClearExceptions();
}
/*!
@ -229,7 +229,7 @@ bool QJniEnvironment::registerNativeMethods(const char *className, JNINativeMeth
jclass clazz = d->jniEnv->GetObjectClass(classObject.object());
if (d->jniEnv->RegisterNatives(clazz, methods, size) < 0) {
exceptionCheckAndClear();
checkAndClearExceptions();
d->jniEnv->DeleteLocalRef(clazz);
return false;
}
@ -248,7 +248,7 @@ bool QJniEnvironment::registerNativeMethods(const char *className, JNINativeMeth
*/
/*!
\fn QJniEnvironment::exceptionCheckAndClear(OutputMode outputMode = OutputMode::Verbose)
\fn QJniEnvironment::checkAndClearExceptions(OutputMode outputMode = OutputMode::Verbose)
Cleans any pending exceptions either silently or reporting stack backtrace,
depending on the \a outputMode.
@ -260,7 +260,7 @@ bool QJniEnvironment::registerNativeMethods(const char *className, JNINativeMeth
\return \c true when a pending exception was cleared.
*/
bool QJniEnvironment::exceptionCheckAndClear(QJniEnvironment::OutputMode outputMode)
bool QJniEnvironment::checkAndClearExceptions(QJniEnvironment::OutputMode outputMode)
{
if (Q_UNLIKELY(d->jniEnv->ExceptionCheck())) {
if (outputMode != OutputMode::Silent)
@ -274,7 +274,7 @@ bool QJniEnvironment::exceptionCheckAndClear(QJniEnvironment::OutputMode outputM
}
/*!
\fn QJniEnvironment::exceptionCheckAndClear(JNIEnv *env, OutputMode outputMode = OutputMode::Verbose)
\fn QJniEnvironment::checkAndClearExceptions(JNIEnv *env, OutputMode outputMode = OutputMode::Verbose)
Cleans any pending exceptions for \a env, either silently or reporting
stack backtrace, depending on the \a outputMode. This is useful when you
@ -287,7 +287,7 @@ bool QJniEnvironment::exceptionCheckAndClear(QJniEnvironment::OutputMode outputM
\return \c true when a pending exception was cleared.
*/
bool QJniEnvironment::exceptionCheckAndClear(JNIEnv *env, QJniEnvironment::OutputMode outputMode)
bool QJniEnvironment::checkAndClearExceptions(JNIEnv *env, QJniEnvironment::OutputMode outputMode)
{
if (Q_UNLIKELY(env->ExceptionCheck())) {
if (outputMode != OutputMode::Silent)

View File

@ -71,8 +71,8 @@ public:
Verbose
};
bool exceptionCheckAndClear(OutputMode outputMode = OutputMode::Verbose);
static bool exceptionCheckAndClear(JNIEnv *env, OutputMode outputMode = OutputMode::Verbose);
bool checkAndClearExceptions(OutputMode outputMode = OutputMode::Verbose);
static bool checkAndClearExceptions(JNIEnv *env, OutputMode outputMode = OutputMode::Verbose);
private:

View File

@ -291,11 +291,11 @@ void QtAndroidPrivate::handleResume()
static void setAndroidSdkVersion(JNIEnv *env)
{
jclass androidVersionClass = env->FindClass("android/os/Build$VERSION");
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return;
jfieldID androidSDKFieldID = env->GetStaticFieldID(androidVersionClass, "SDK_INT", "I");
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return;
g_androidSdkVersion = env->GetStaticIntField(androidVersionClass, androidSDKFieldID);
@ -331,42 +331,42 @@ jint QtAndroidPrivate::initJNI(JavaVM *vm, JNIEnv *env)
{
jclass jQtNative = env->FindClass("org/qtproject/qt/android/QtNative");
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return JNI_ERR;
jmethodID activityMethodID = env->GetStaticMethodID(jQtNative,
"activity",
"()Landroid/app/Activity;");
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return JNI_ERR;
jobject activity = env->CallStaticObjectMethod(jQtNative, activityMethodID);
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return JNI_ERR;
jmethodID serviceMethodID = env->GetStaticMethodID(jQtNative,
"service",
"()Landroid/app/Service;");
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return JNI_ERR;
jobject service = env->CallStaticObjectMethod(jQtNative, serviceMethodID);
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return JNI_ERR;
jmethodID classLoaderMethodID = env->GetStaticMethodID(jQtNative,
"classLoader",
"()Ljava/lang/ClassLoader;");
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return JNI_ERR;
jobject classLoader = env->CallStaticObjectMethod(jQtNative, classLoaderMethodID);
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return JNI_ERR;
setAndroidSdkVersion(env);
@ -394,7 +394,7 @@ jint QtAndroidPrivate::initJNI(JavaVM *vm, JNIEnv *env)
const bool regOk = (env->RegisterNatives(jQtNative, methods, sizeof(methods) / sizeof(methods[0])) == JNI_OK);
if (!regOk && QJniEnvironment::exceptionCheckAndClear(env))
if (!regOk && QJniEnvironment::checkAndClearExceptions(env))
return JNI_ERR;
g_runPendingCppRunnablesMethodID = env->GetStaticMethodID(jQtNative,
@ -512,7 +512,7 @@ void QtAndroidPrivate::requestPermissions(JNIEnv *env,
QJniEnvironment env;
jclass clazz = env->FindClass("java/lang/String");
if (env.exceptionCheckAndClear())
if (env.checkAndClearExceptions())
return;
auto array = env->NewObjectArray(permissions.size(), clazz, nullptr);

View File

@ -132,7 +132,7 @@ QT_BEGIN_NAMESPACE
\note The user must handle exceptions manually when doing JNI calls using \c JNIEnv directly.
It is unsafe to make other JNI calls when exceptions are pending. For more information, see
QJniEnvironment::exceptionCheckAndClear().
QJniEnvironment::checkAndClearExceptions().
\section1 Java Native Methods
@ -346,7 +346,7 @@ inline static jclass loadClass(const QByteArray &className, JNIEnv *env, bool bi
"(Ljava/lang/String;)Ljava/lang/Class;",
stringName.object());
if (!QJniEnvironment::exceptionCheckAndClear(env) && classObject.isValid())
if (!QJniEnvironment::checkAndClearExceptions(env) && classObject.isValid())
clazz = static_cast<jclass>(env->NewGlobalRef(classObject.object()));
cachedClasses->insert(key, clazz);
@ -366,7 +366,7 @@ static inline jmethodID getMethodID(JNIEnv *env,
jmethodID id = isStatic ? env->GetStaticMethodID(clazz, name, signature)
: env->GetMethodID(clazz, name, signature);
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return nullptr;
return id;
@ -420,7 +420,7 @@ static inline jfieldID getFieldID(JNIEnv *env,
jfieldID id = isStatic ? env->GetStaticFieldID(clazz, name, signature)
: env->GetFieldID(clazz, name, signature);
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return nullptr;
return id;
@ -479,7 +479,7 @@ jclass QtAndroidPrivate::findClass(const char *className, JNIEnv *env)
return it.value();
jclass fclazz = env->FindClass(className);
if (!QJniEnvironment::exceptionCheckAndClear(env)) {
if (!QJniEnvironment::checkAndClearExceptions(env)) {
clazz = static_cast<jclass>(env->NewGlobalRef(fclazz));
env->DeleteLocalRef(fclazz);
}
@ -726,7 +726,7 @@ inline static QJniObject getCleanJniObject(jobject obj)
return QJniObject();
QJniEnvironment env;
if (env.exceptionCheckAndClear()) {
if (env.checkAndClearExceptions()) {
env->DeleteLocalRef(obj);
return QJniObject();
}
@ -775,7 +775,7 @@ QJniObject QJniObject::callObjectMethodV(const char *methodName,
jmethodID id = getCachedMethodID(env, d->m_jclass, d->m_className, methodName, signature);
if (id) {
res = env->CallObjectMethodV(d->m_jobject, id, args);
if (env.exceptionCheckAndClear()) {
if (env.checkAndClearExceptions()) {
env->DeleteLocalRef(res);
res = nullptr;
}
@ -799,7 +799,7 @@ QJniObject QJniObject::callStaticObjectMethodV(const char *className,
methodName, signature, true);
if (id) {
res = env->CallStaticObjectMethodV(clazz, id, args);
if (env.exceptionCheckAndClear()) {
if (env.checkAndClearExceptions()) {
env->DeleteLocalRef(res);
res = nullptr;
}
@ -846,7 +846,7 @@ Q_CORE_EXPORT void QJniObject::callMethod<void>(const char *methodName, const ch
va_start(args, signature);
env->CallVoidMethodV(d->m_jobject, id, args);
va_end(args);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}
@ -894,7 +894,7 @@ Q_CORE_EXPORT void QJniObject::callStaticMethod<void>(const char *className,
va_start(args, signature);
env->CallStaticVoidMethodV(clazz, id, args);
va_end(args);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}
}
@ -942,7 +942,7 @@ Q_CORE_EXPORT void QJniObject::callStaticMethod<void>(jclass clazz,
va_start(args, signature);
env->CallStaticVoidMethodV(clazz, id, args);
va_end(args);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}
}
@ -961,7 +961,7 @@ Q_CORE_EXPORT void QJniObject::callStaticMethodV<void>(const char *className,
signature, true);
if (id) {
env->CallStaticVoidMethodV(clazz, id, args);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}
}
@ -976,7 +976,7 @@ Q_CORE_EXPORT void QJniObject::callStaticMethodV<void>(jclass clazz,
jmethodID id = getMethodID(env, clazz, methodName, signature, true);
if (id) {
env->CallStaticVoidMethodV(clazz, id, args);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}
@ -1005,7 +1005,7 @@ Q_CORE_EXPORT void QJniObject::callMethodV<void>(const char *methodName, const c
jmethodID id = getCachedMethodID(env, d->m_jclass, d->m_className, methodName, signature);
if (id) {
env->CallVoidMethodV(d->m_jobject, id, args);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}
@ -1021,7 +1021,7 @@ template <> Q_CORE_EXPORT Type QJniObject::callMethod<Type>(const char *methodNa
va_start(args, signature); \
res = env->Call##MethodName##MethodV(d->m_jobject, id, args); \
va_end(args); \
if (env.exceptionCheckAndClear()) \
if (env.checkAndClearExceptions()) \
res = 0; \
} \
return res; \
@ -1047,7 +1047,7 @@ template <> Q_CORE_EXPORT Type QJniObject::callStaticMethod<Type>(const char *cl
va_start(args, signature); \
res = env->CallStatic##MethodName##MethodV(clazz, id, args); \
va_end(args); \
if (env.exceptionCheckAndClear()) \
if (env.checkAndClearExceptions()) \
res = 0; \
} \
} \
@ -1073,7 +1073,7 @@ template <> Q_CORE_EXPORT Type QJniObject::callStaticMethod<Type>(jclass clazz,
va_start(args, signature); \
res = env->CallStatic##MethodName##MethodV(clazz, id, args); \
va_end(args); \
if (env.exceptionCheckAndClear()) \
if (env.checkAndClearExceptions()) \
res = 0; \
} \
} \
@ -1093,7 +1093,7 @@ Q_CORE_EXPORT Type QJniObject::callMethodV<Type>(const char *methodName, const c
jmethodID id = getCachedMethodID(env, d->m_jclass, d->m_className, methodName, signature);\
if (id) {\
res = env->Call##MethodName##MethodV(d->m_jobject, id, args);\
if (env.exceptionCheckAndClear()) \
if (env.checkAndClearExceptions()) \
res = 0; \
}\
return res;\
@ -1112,7 +1112,7 @@ Q_CORE_EXPORT Type QJniObject::callStaticMethodV<Type>(const char *className,\
signature, true);\
if (id) {\
res = env->CallStatic##MethodName##MethodV(clazz, id, args);\
if (env.exceptionCheckAndClear()) \
if (env.checkAndClearExceptions()) \
res = 0; \
}\
}\
@ -1129,7 +1129,7 @@ Q_CORE_EXPORT Type QJniObject::callStaticMethodV<Type>(jclass clazz,\
jmethodID id = getMethodID(env, clazz, methodName, signature, true);\
if (id) {\
res = env->CallStatic##MethodName##MethodV(clazz, id, args);\
if (env.exceptionCheckAndClear()) \
if (env.checkAndClearExceptions()) \
res = 0; \
}\
return res;\
@ -1357,7 +1357,7 @@ Q_CORE_EXPORT void QJniObject::setStaticField<jobject>(const char *className,
jfieldID id = getCachedFieldID(env, clazz, className, fieldName, signature, true);
if (id) {
env->SetStaticObjectField(clazz, id, value);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}
@ -1377,7 +1377,7 @@ template <> Q_CORE_EXPORT void QJniObject::setStaticField<jobject>(jclass clazz,
if (id) {
env->SetStaticObjectField(clazz, id, value);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}
@ -1423,7 +1423,7 @@ template <> Q_CORE_EXPORT Type QJniObject::getField<Type>(const char *fieldName)
jfieldID id = getCachedFieldID(env, d->m_jclass, d->m_className, fieldName, Signature); \
if (id) {\
res = env->Get##FieldName##Field(d->m_jobject, id); \
if (env.exceptionCheckAndClear()) \
if (env.checkAndClearExceptions()) \
res = 0; \
} \
return res;\
@ -1440,7 +1440,7 @@ Q_CORE_EXPORT Type QJniObject::getStaticField<Type>(const char *className, const
if (!id) \
return 0; \
Type res = env->GetStatic##FieldName##Field(clazz, id); \
if (env.exceptionCheckAndClear()) \
if (env.checkAndClearExceptions()) \
res = 0; \
return res;\
} \
@ -1452,7 +1452,7 @@ Q_CORE_EXPORT Type QJniObject::getStaticField<Type>(jclass clazz, const char *fi
jfieldID id = getFieldID(env, clazz, fieldName, Signature, true);\
if (id) {\
res = env->GetStatic##FieldName##Field(clazz, id);\
if (env.exceptionCheckAndClear()) \
if (env.checkAndClearExceptions()) \
res = 0; \
}\
return res;\
@ -1469,7 +1469,7 @@ template <> Q_CORE_EXPORT void QJniObject::setStaticField<Type>(const char *clas
if (!id) \
return; \
env->SetStatic##FieldName##Field(clazz, id, value); \
env.exceptionCheckAndClear(); \
env.checkAndClearExceptions(); \
}\
template <> Q_CORE_EXPORT void QJniObject::setStaticField<Type>(jclass clazz,\
const char *fieldName,\
@ -1479,7 +1479,7 @@ template <> Q_CORE_EXPORT void QJniObject::setStaticField<Type>(jclass clazz,\
jfieldID id = getFieldID(env, clazz, fieldName, Signature, true);\
if (id) {\
env->SetStatic##FieldName##Field(clazz, id, value);\
env.exceptionCheckAndClear();\
env.checkAndClearExceptions();\
}\
}\
template <> Q_CORE_EXPORT void QJniObject::setField<Type>(const char *fieldName, Type value) \
@ -1488,7 +1488,7 @@ template <> Q_CORE_EXPORT void QJniObject::setField<Type>(const char *fieldName,
jfieldID id = getCachedFieldID(env, d->m_jclass, d->m_className, fieldName, Signature); \
if (id) { \
env->Set##FieldName##Field(d->m_jobject, id, value); \
env.exceptionCheckAndClear(); \
env.checkAndClearExceptions(); \
} \
} \
@ -1631,7 +1631,7 @@ void QJniObject::setField<jobject>(const char *fieldName, const char *signature,
jfieldID id = getCachedFieldID(env, d->m_jclass, d->m_className, fieldName, signature);
if (id) {
env->SetObjectField(d->m_jobject, id, value);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}
@ -1644,7 +1644,7 @@ void QJniObject::setField<jobjectArray>(const char *fieldName,
jfieldID id = getCachedFieldID(env, d->m_jclass, d->m_className, fieldName, signature);
if (id) {
env->SetObjectField(d->m_jobject, id, value);
env.exceptionCheckAndClear();
env.checkAndClearExceptions();
}
}

View File

@ -135,12 +135,12 @@ Java_org_qtproject_qt_android_ExtractStyle_extractChunkInfo20(JNIEnv *env, jobje
env->GetByteArrayRegion(chunkObj, 0, chunkSize,
reinterpret_cast<jbyte*>(storage));
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
return 0;
jintArray res = Java_org_qtproject_qt_android_ExtractStyle_extractNativeChunkInfo20(env, obj,
long(storage));
if (QJniEnvironment::exceptionCheckAndClear(env))
if (QJniEnvironment::checkAndClearExceptions(env))
res = nullptr;
return res;

View File

@ -71,11 +71,11 @@ void tst_QJniEnvironment::jniEnv()
env->ExceptionClear();
QVERIFY(env->FindClass("java/lang/Object"));
QVERIFY(!QJniEnvironment::exceptionCheckAndClear(env));
QVERIFY(!QJniEnvironment::checkAndClearExceptions(env));
// try to find a nonexistent class
QVERIFY(!env->FindClass("this/doesnt/Exist"));
QVERIFY(QJniEnvironment::exceptionCheckAndClear(env));
QVERIFY(QJniEnvironment::checkAndClearExceptions(env));
// try to find an existing class with QJniEnvironment
QJniEnvironment env;
@ -86,7 +86,7 @@ void tst_QJniEnvironment::jniEnv()
// clear exception with member function
QVERIFY(!env->FindClass("this/doesnt/Exist"));
QVERIFY(env.exceptionCheckAndClear());
QVERIFY(env.checkAndClearExceptions());
}
// The env does not detach automatically, even if it goes out of scope. The only way it can