google / google/error-prone

Calling hasFoo on a protocol buffer when foo has a default value.

Open
#97 1 comment 0 reactions 0 assignees View on GitHub
migrated Priority-Low Status-Accepted Type-NewCheck
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.