Blame SOURCES/0018-qqmlistmodel-Fix-crash-when-modelCache-is-null.patch

383017
From 83100a84f2b0068b4cf725896bbb810415908334 Mon Sep 17 00:00:00 2001
383017
From: Maximilian Goldstein <max.goldstein@qt.io>
383017
Date: Tue, 8 Dec 2020 09:26:36 +0100
383017
Subject: [PATCH 18/28] qqmlistmodel: Fix crash when modelCache is null
383017
383017
Fixes: QTBUG-89173
383017
Change-Id: Ife82518808fc5504ec42407e80ed3de89ed4adeb
383017
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
383017
(cherry picked from commit c3860cd04bbc089ef95bc441a1f8f1e46f9606f8)
383017
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
383017
---
383017
 src/qmlmodels/qqmllistmodel.cpp               |  2 +-
383017
 .../qml/qqmllistmodel/tst_qqmllistmodel.cpp   | 22 +++++++++++++++++++
383017
 2 files changed, 23 insertions(+), 1 deletion(-)
383017
383017
diff --git a/src/qmlmodels/qqmllistmodel.cpp b/src/qmlmodels/qqmllistmodel.cpp
383017
index e07951cab3..8830e08097 100644
383017
--- a/src/qmlmodels/qqmllistmodel.cpp
383017
+++ b/src/qmlmodels/qqmllistmodel.cpp
383017
@@ -703,7 +703,7 @@ void ListModel::set(int elementIndex, QV4::Object *object, ListModel::SetElement
383017
         } else if (propertyValue->isNullOrUndefined()) {
383017
             if (reason == SetElement::WasJustInserted) {
383017
                 QQmlError err;
383017
-                auto memberName = propertyName->toString(m_modelCache->engine())->toQString();
383017
+                auto memberName = propertyName->toString(v4)->toQString();
383017
                 err.setDescription(QString::fromLatin1("%1 is %2. Adding an object with a %2 member does not create a role for it.").arg(memberName, propertyValue->isNull() ? QLatin1String("null") : QLatin1String("undefined")));
383017
                 qmlWarning(nullptr, err);
383017
             } else {
383017
diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
383017
index d54e3467b7..1953798a15 100644
383017
--- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
383017
+++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
383017
@@ -130,6 +130,7 @@ private slots:
383017
     void dynamic_roles_crash_QTBUG_38907();
383017
     void nestedListModelIteration();
383017
     void undefinedAppendShouldCauseError();
383017
+    void nullPropertyCrash();
383017
 };
383017
 
383017
 bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object)
383017
@@ -1723,6 +1724,27 @@ void tst_qqmllistmodel::undefinedAppendShouldCauseError()
383017
     QScopedPointer<QObject>(component.create());
383017
 }
383017
 
383017
+// QTBUG-89173
383017
+void tst_qqmllistmodel::nullPropertyCrash()
383017
+{
383017
+    QQmlEngine engine;
383017
+    QQmlComponent component(&engine);
383017
+    component.setData(
383017
+            R"(import QtQuick 2.15
383017
+            ListView {
383017
+                model: ListModel { id: listModel }
383017
+
383017
+                delegate: Item {}
383017
+
383017
+                Component.onCompleted: {
383017
+                    listModel.append({"a": "value1", "b":[{"c":"value2"}]})
383017
+                    listModel.append({"a": "value2", "b":[{"c":null}]})
383017
+                }
383017
+            })",
383017
+            QUrl());
383017
+    QTest::ignoreMessage(QtMsgType::QtWarningMsg, "<Unknown File>: c is null. Adding an object with a null member does not create a role for it.");
383017
+    QScopedPointer<QObject>(component.create());
383017
+}
383017
 
383017
 QTEST_MAIN(tst_qqmllistmodel)
383017
 
383017
-- 
383017
2.31.1
383017