szaszm commented on a change in pull request #1040: URL: https://github.com/apache/nifi-minifi-cpp/pull/1040#discussion_r605665253
########## File path: extensions/mqtt/processors/AbstractMQTTProcessor.cpp ########## @@ -85,8 +86,9 @@ void AbstractMQTTProcessor::onSchedule(const std::shared_ptr<core::ProcessContex logger_->log_debug("AbstractMQTTProcessor: PassWord [%s]", passWord_); } value = ""; - if (context->getProperty(CleanSession.getName(), value) && !value.empty() && - org::apache::nifi::minifi::utils::StringUtils::StringToBool(value, cleanSession_)) { + utils::optional<bool> cleanSession_parsed; + if (context->getProperty(CleanSession.getName(), value) && (cleanSession_parsed = org::apache::nifi::minifi::utils::StringUtils::toBool(value))) { + cleanSession_ = cleanSession_parsed.value(); Review comment: ~Calling `value()` on an empty optional will throw, which is most likely not what we want here. The assignment should only be attempted when the optional is not empty.~ Assignment in the condition gives me uneasy feelings. Here's an alternative involving an [immediately invoked lambda](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-lambda-init) and the mutable temporary `value`/`property_value` moved to a smaller scope. 100% optional, just an idea. ```suggestion const auto cleanSession_parsed = [this, &] -> utils::optional<bool> { std::string property_value; if (!context->getProperty(CleanSession.getName(), value)) return utils::nullopt; return utils::StringUtils::toBool(property_value); }(); if (cleanSession_parsed) { cleanSession_ = *cleanSession_parsed; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org