Skip to content

[Ruby] JRuby - type of oneof is always nil after decoding #7831

@TCRuys

Description

@TCRuys

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions