Skip to content

jruby: protobuf fields should be defined as methods #9202

Closed
@HoneyryderChuck

Description

@HoneyryderChuck

What version of protobuf and what language are you using?
Version: 3.19.1
Language: Ruby (JRuby 9.3)

What operating system (Linux, Windows, ...) and version?

Darwin.

What did you do?

First, thanks a lot for reenabling jruby support 🙏

I have code which checks whether a certain field exists.I use the idiomatic .respond_to? in CRuby. Things aren't working the same way in JRuby however.

What did you expect to see

I'd expect the check to work. To compare, here's how it works in CRuby (v3.0):

# given a Google::Protobuf::Duration message
message.respond_to?(:seconds) #=> true
# although the method isn't defined
message.methods - Object.instance_methods #=>  [:to_f, :method_missing, :[], :[]=, :to_h, :to_json, :to_proto]

What did you see instead?

In Jruby, I don't get the same result for the respond_to? call, even if I can call .seconds.

message.respond_to?(:seconds) #=> false
message.seconds #=> 123

I suspect this happens because .seconds gets sent to method_missing, which then infers the value of the field; and the respective .respond_to_missing? method isn't defined, which makes my example break.

Metadata

Metadata

Assignees

Labels

bugjrubyIssues unique to the JRuby interpreterruby

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions