Skip to content

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

Description

@cushon

Original issue 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions