summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2021-03-16 12:30:01 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-01-20 14:52:38 +0000
commit466834d0ffdea8255a78d0c6d5407ecb3fabfd9c (patch)
tree13611b41a7b2bb98e5c3779e0a9ac3d50f8db6cd
parentdbe416140b788e3b6287782888d654123117d4e3 (diff)
Android: Protect against a null Locale object when calling getLocale
Change-Id: I9a22b69f709f4b393d264fe1037e56e3c18d4844 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit c88a00a9b45448d2d9693cfd5faa9b1c0918ff47) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/tts/android/jar/src/org/qtproject/qt/android/speech/QtTextToSpeech.java2
-rw-r--r--src/plugins/tts/android/src/qtexttospeech_android.cpp12
2 files changed, 9 insertions, 5 deletions
diff --git a/src/plugins/tts/android/jar/src/org/qtproject/qt/android/speech/QtTextToSpeech.java b/src/plugins/tts/android/jar/src/org/qtproject/qt/android/speech/QtTextToSpeech.java
index ddbc253..1290d9f 100644
--- a/src/plugins/tts/android/jar/src/org/qtproject/qt/android/speech/QtTextToSpeech.java
+++ b/src/plugins/tts/android/jar/src/org/qtproject/qt/android/speech/QtTextToSpeech.java
@@ -228,6 +228,8 @@ public class QtTextToSpeech
{
//Log.d(TAG, "getLocale: " + mLocale);
final Locale language = mTts.getLanguage();
+ if (language == null)
+ return null;
String languageCode = language.getLanguage();
String countryCode = language.getCountry();
diff --git a/src/plugins/tts/android/src/qtexttospeech_android.cpp b/src/plugins/tts/android/src/qtexttospeech_android.cpp
index 55d3f85..2741ee6 100644
--- a/src/plugins/tts/android/src/qtexttospeech_android.cpp
+++ b/src/plugins/tts/android/src/qtexttospeech_android.cpp
@@ -292,11 +292,13 @@ QList<QLocale> QTextToSpeechEngineAndroid::availableLocales() const
result.reserve(count);
for (int i = 0; i < count; ++i) {
auto locale = locales.callMethod<jobject>("get", i);
- auto localeLanguage = locale.callMethod<jstring>("getLanguage").toString();
- auto localeCountry = locale.callMethod<jstring>("getCountry").toString();
- if (!localeCountry.isEmpty())
- localeLanguage += QString("_%1").arg(localeCountry).toUpper();
- result << QLocale(localeLanguage);
+ if (locale.isValid()) {
+ auto localeLanguage = locale.callMethod<jstring>("getLanguage").toString();
+ auto localeCountry = locale.callMethod<jstring>("getCountry").toString();
+ if (!localeCountry.isEmpty())
+ localeLanguage += QString("_%1").arg(localeCountry).toUpper();
+ result << QLocale(localeLanguage);
+ }
}
return result;
}