-
Notifications
You must be signed in to change notification settings - Fork 15.9k
Closed
Labels
Description
What version of protobuf and what language are you using?
Version: 3.13.0
Language: Ruby
What operating system (Linux, Windows, ...) and version?
Linux Ubuntu 16.x and 18.x.
What runtime / compiler are you using (e.g., python version or gcc version)
Ruby 2.6.3 and JRuby 9.2.9.0.
But this bug is already in protobuf for JRuby for a long time...
What did you do?
Consider the following Ruby script:
require 'google/protobuf'
def assert(lhs, rhs)
raise Exception, "#{lhs} != #{rhs}" unless lhs == rhs
end
pool = Google::Protobuf::DescriptorPool.new
pool.build do
add_message "OneofMessage" do
oneof :my_oneof do
optional :a, :string, 1
optional :b, :int32, 2
optional :c, :bool, 3
end
end
end
OneofMessage = pool.lookup('OneofMessage').msgclass
m1 = OneofMessage.new
m1.b = 666
assert(m1.b, 666)
assert(m1.my_oneof, :b)
bytes = OneofMessage.encode(m1)
m2 = OneofMessage.decode(bytes)
assert(m2.b, 666)
assert(m2.my_oneof, :b)
What did you expect to see
Under Ruby this script does not report any assertion violations, as expected.
What did you see instead?
Under JRuby, the last assert fails as m2.my_oneof is nil instead of :b.
This means that for a receiver of message it is not clear which of the fields of the oneof has been set.