adamdebreceni commented on a change in pull request #797:
URL: https://github.com/apache/nifi-minifi-cpp/pull/797#discussion_r431200537
##########
File path: libminifi/include/core/Property.h
##########
@@ -129,41 +133,32 @@ class Property {
template<typename T = std::string>
void setValue(const T &value) {
- PropertyValue vn = default_value_;
- vn = value;
- if (validator_) {
- vn.setValidator(validator_);
- ValidationResult result = validator_->validate(name_, vn.getValue());
- if (!result.valid()) {
- // throw some exception?
- }
- } else {
- vn.setValidator(core::StandardValidators::VALID);
- }
if (!is_collection_) {
values_.clear();
- values_.push_back(vn);
+ values_.push_back(default_value_);
} else {
- values_.push_back(vn);
+ values_.push_back(default_value_);
}
+ PropertyValue& vn = values_.back();
+ vn.setValidator(validator_ ? validator_ : core::StandardValidators::VALID);
+ vn = value;
+ ValidationResult result = vn.validate(name_);
+ if(!result.valid())
+ throw utils::InvalidValueException(name_ + " value validation failed");
}
- void setValue(PropertyValue &vn) {
- if (validator_) {
- vn.setValidator(validator_);
- ValidationResult result = validator_->validate(name_, vn.getValue());
- if (!result.valid()) {
- // throw some exception?
- }
- } else {
- vn.setValidator(core::StandardValidators::VALID);
- }
+ void setValue(PropertyValue &newValue) {
if (!is_collection_) {
values_.clear();
- values_.push_back(vn);
+ values_.push_back(newValue);
} else {
- values_.push_back(vn);
+ values_.push_back(newValue);
}
+ PropertyValue& vn = values_.back();
+ vn.setValidator(validator_ ? validator_ : core::StandardValidators::VALID);
Review comment:
it sets the validator in the PropertyValue, if we didn't the incoming
`newValue`'s validator would remain in the copy, yes we could also just clear
the validator as most places interpret the absence of a validator as being
valid, but I find it unappealing, imo we should always have a non-empty
validator instance
----------------------------------------------------------------
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:
[email protected]