JNI: Warn if classes are resolved with wrong syntax

Amends 39294317e0, after which class names have to be slash-separated.

Change-Id: I5b8415b711f4deed9b6134eccd3232f299b1ef4d
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
This commit is contained in:
Volker Hilsheimer 2023-10-04 17:54:46 +02:00
parent a20a6ae7ea
commit 7d3417fbfc

View File

@ -360,7 +360,14 @@ static QJniObject getCleanJniObject(jobject object)
jclass QtAndroidPrivate::findClass(const char *className, JNIEnv *env)
{
Q_ASSERT(env);
const QByteArray classNameArray(className);
QByteArray classNameArray(className);
#ifdef QT_DEBUG
if (classNameArray.contains('.')) {
qWarning("QtAndroidPrivate::findClass: className '%s' should use slash separators!",
className);
}
#endif
classNameArray.replace('.', '/');
jclass clazz = getCachedClass(classNameArray);
if (clazz)
return clazz;
@ -374,7 +381,7 @@ jclass QtAndroidPrivate::findClass(const char *className, JNIEnv *env)
// JNIEnv::FindClass wants "a fully-qualified class name or an array type signature"
// which is a slash-separated class name.
jclass localClazz = env->FindClass(className);
jclass localClazz = env->FindClass(classNameArray.constData());
if (localClazz) {
clazz = static_cast<jclass>(env->NewGlobalRef(localClazz));
env->DeleteLocalRef(localClazz);