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 93400fe1761849e97c4e4c228eeae3b5e60e0047..55826163aa54edfe23ade2173c535c6593f71e09 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); }