Calling hasFoo on a protocol buffer when foo has a default value.
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
_[Original issue](https://code.google.com/p/error-prone/issues/detail?id=97) created by **gmoura@google.com** on 2013-02-27 at 08:10 PM_
---
The problem is described in detail in this thread:
https://groups.google.com/a/google.com/forum/?fromgroups=#!search/protocol$20buffer$20set$20optional$20values/nehen/QnlmlEEEC_g/z9CUEb76aBQJ
But here's a summary. Consider the following proto:
message Query {
optional bool use_new_backend = 1 [default = true];
}
The new backend is to be used by default, so clients might not set it. Now consider the following server side code:
if (query.hasUseNewBackend() && query.getUseNewBackend()) {
useNewBackend();
} else {
useOldBackend();
}
This would be incorrectly using the old backend. When a default is set in the protocol buffer, you shouldn't need to call "hasFoo()" and more-over, doing it may introduce bugs.
Contributor guide
Assessment
This issue has not been assessed yet.