From 257195e812445ca45be2f813a0a5949726e334bb Mon Sep 17 00:00:00 2001 From: armar-user <armar6@kit> Date: Fri, 9 Jun 2023 08:13:22 +0200 Subject: [PATCH] fix error when adding NULL to dict --- .../aron/core/data/variant/container/Dict.cpp | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.cpp b/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.cpp index 93400fe17..55826163a 100644 --- a/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.cpp +++ b/source/RobotAPI/libraries/aron/core/data/variant/container/Dict.cpp @@ -161,6 +161,8 @@ namespace armarx::aron::data void Dict::addElement(const std::string& key, const VariantPtr& data) { + // Please note that the data may be null (indicating that a non existing maybetype has been added) + if (hasElement(key)) { ARMARX_TRACE; @@ -173,6 +175,8 @@ namespace armarx::aron::data void Dict::addElementCopy(const std::string& key, const VariantPtr& data) { + // Please note that the data may be null (indicating that a non existing maybetype has been added) + if (hasElement(key)) { ARMARX_TRACE; @@ -213,11 +217,16 @@ namespace armarx::aron::data void Dict::setElement(const std::string& key, const VariantPtr& data) { - const auto& p = data->getPath(); - if (not p.hasDirectPrefix(this->getPath())) + // Please note that the data may be null (indicating that a non existing maybetype has been added) + + if (data) { - ARMARX_WARNING << "An element added to a dict does not have a correct path set. This " - "may cause errors. Please use setElemetCopy() instead."; + const auto& p = data->getPath(); + if (not p.hasDirectPrefix(this->getPath())) + { + ARMARX_WARNING << "An element added to a dict does not have a correct path set. This " + "may cause errors. Please use setElemetCopy() instead."; + } } this->childrenNavigators[key] = data; @@ -234,8 +243,14 @@ namespace armarx::aron::data void Dict::setElementCopy(const std::string& key, const VariantPtr& data) { - Path newPath = getPath().withElement(key); - auto copy = data->cloneAsVariant(newPath); + // Please note that the data may be null (indicating that a non existing maybetype has been added) + + VariantPtr copy = nullptr; + if (data) + { + Path newPath = getPath().withElement(key); + copy = data->cloneAsVariant(newPath); + } setElement(key, copy); } -- GitLab