JNI: check if clazz is null before doing a jni call

Also add missing \since keyword.

Task-number: QTBUG-92952
Pick-to: 6.2
Change-Id: Ia1472f04955809fb5132a4b6239dbcbdf63cca93
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
Assam Boudjelthia 2021-06-01 22:23:22 +03:00
parent 49b51425bf
commit 60e104aed8

View File

@ -217,14 +217,18 @@ jclass QJniEnvironment::findClass(const char *className)
A usecase for this method is searching for class methods and caching their A usecase for this method is searching for class methods and caching their
IDs, so that they could later be used for calling the methods. IDs, so that they could later be used for calling the methods.
\since 6.2
*/ */
jmethodID QJniEnvironment::findMethod(jclass clazz, const char *methodName, const char *signature) jmethodID QJniEnvironment::findMethod(jclass clazz, const char *methodName, const char *signature)
{ {
jmethodID id = d->jniEnv->GetMethodID(clazz, methodName, signature); if (clazz) {
if (checkAndClearExceptions(d->jniEnv)) jmethodID id = d->jniEnv->GetMethodID(clazz, methodName, signature);
return nullptr; if (!checkAndClearExceptions(d->jniEnv))
return id;
}
return id; return nullptr;
} }
/*! /*!
@ -247,14 +251,18 @@ jmethodID QJniEnvironment::findMethod(jclass clazz, const char *methodName, cons
methodId, methodId,
javaMessage.object<jstring>()); javaMessage.object<jstring>());
\endcode \endcode
\since 6.2
*/ */
jmethodID QJniEnvironment::findStaticMethod(jclass clazz, const char *methodName, const char *signature) jmethodID QJniEnvironment::findStaticMethod(jclass clazz, const char *methodName, const char *signature)
{ {
jmethodID id = d->jniEnv->GetStaticMethodID(clazz, methodName, signature); if (clazz) {
if (checkAndClearExceptions(d->jniEnv)) jmethodID id = d->jniEnv->GetStaticMethodID(clazz, methodName, signature);
return nullptr; if (!checkAndClearExceptions(d->jniEnv))
return id;
}
return id; return nullptr;
} }