Hold references to zone IDs alive during use

Restore holding of a getID() call's return in a QJNIObjectPrivate
eliminated in commit 78cde1bfd94521bbe4972f31a79c959d0990ea77; this
keeps the Java internal object alive for its lifetime, where it might
otherwise be garbage-collected before we're done with it.

Fixes: QTBUG-88610
Change-Id: Id65b059012f7bd3377a6562c1b647feb75a13679
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
(cherry picked from commit d5eda37baaea20b2411b6ef1ca0d41a2a71a06a6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Edward Welbourne 2020-11-24 14:09:30 +01:00 committed by Qt Cherry-pick Bot
parent c17643b64f
commit 198a985c09

View File

@ -48,6 +48,10 @@ QT_BEGIN_NAMESPACE
Private
Android implementation
Note that a QJNIObjectPrivate manages a global reference, so it serves as an
owning smart-pointer, ensuring an object doesn't get garbage-collected
before we're done with it.
*/
// Create the system default time zone
@ -57,7 +61,8 @@ QAndroidTimeZonePrivate::QAndroidTimeZonePrivate()
// Keep in sync with systemTimeZoneId():
androidTimeZone = QJNIObjectPrivate::callStaticObjectMethod(
"java.util.TimeZone", "getDefault", "()Ljava/util/TimeZone;");
m_id = androidTimeZone.callObjectMethod("getID", "()Ljava/lang/String;").toString().toUtf8();
const QJNIObjectPrivate id = androidTimeZone.callObjectMethod("getID", "()Ljava/lang/String;");
m_id = id.toString().toUtf8();
}
// Create a named time zone
@ -247,7 +252,8 @@ QByteArray QAndroidTimeZonePrivate::systemTimeZoneId() const
// Keep in sync with default constructor:
QJNIObjectPrivate androidSystemTimeZone = QJNIObjectPrivate::callStaticObjectMethod(
"java.util.TimeZone", "getDefault", "()Ljava/util/TimeZone;");
return androidSystemTimeZone.callObjectMethod<jstring>("getID").toString().toUtf8();
const QJNIObjectPrivate id = androidSystemTimeZone.callObjectMethod<jstring>("getID");
return id.toString().toUtf8();
}
QList<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const