summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Kunal Sareen <kunal.sareen@anu.edu.au> 2024-09-19 07:58:51 +0000
committer Jiakai Zhang <jiakaiz@google.com> 2024-09-20 12:41:23 +0000
commit68742f619ed4475de413ced479aa2517bf3fd93a (patch)
tree903f4b5bfb1b80418a41e63fc4b39debde3af959
parent888d691d61d1f3596fd67ce151eb72e62fb6cf5e (diff)
Fix incorrect assertion checking default values of system properties
Change-Id: I13edef7ae171078fc3a16d95c311fb9737b136dd
-rw-r--r--odrefresh/odr_config.h6
-rw-r--r--odrefresh/odrefresh.cc11
2 files changed, 13 insertions, 4 deletions
diff --git a/odrefresh/odr_config.h b/odrefresh/odr_config.h
index 20eca87898..eb819ee29d 100644
--- a/odrefresh/odr_config.h
+++ b/odrefresh/odr_config.h
@@ -104,6 +104,12 @@ class OdrSystemProperties : public tools::SystemProperties {
auto begin() const { return system_properties_->begin(); }
auto end() const { return system_properties_->end(); }
+ // Return a given property's value if it exists in the map.
+ std::optional<std::string> GetOrNull(const std::string& key) const {
+ auto it = system_properties_->find(key);
+ return it != system_properties_->end() ? std::make_optional(it->second) : std::nullopt;
+ }
+
protected:
std::string GetProperty(const std::string& key) const override {
auto it = system_properties_->find(key);
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index 0110a6ec45..f0b8b44d23 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -1102,12 +1102,15 @@ WARN_UNUSED bool OnDeviceRefresh::CheckSystemPropertiesAreDefault() const {
const OdrSystemProperties& system_properties = config_.GetSystemProperties();
for (const SystemPropertyConfig& system_property_config : *kSystemProperties.get()) {
- std::string property = system_properties.GetOrEmpty(system_property_config.name);
- DCHECK_NE(property, "");
+ // Note that the `kSystemPropertySystemServerCompilerFilterOverride` property has an empty
+ // default value, so we use the `GetOrNull` method and check against nullopt
+ std::optional<std::string> property = system_properties.GetOrNull(system_property_config.name);
+ DCHECK(property.has_value()) << "Property " << system_property_config.name
+ << " does not exist in system properties map!";
- if (property != system_property_config.default_value) {
+ if (*property != system_property_config.default_value) {
LOG(INFO) << "System property " << system_property_config.name << " has a non-default value ("
- << property << ").";
+ << *property << ").";
return false;
}
}