-
Notifications
You must be signed in to change notification settings - Fork 15.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling inspect
on a proto instance causes a NullPointerException
on subsequent to_proto
#9507
Comments
@NC-piercej - We use |
@JasonLunn Here is an example: #!/usr/bin/ruby
require 'google/protobuf'
require 'test/unit'
class InspectTest < Test::Unit::TestCase
def test_type_enum_not_set_with_other_field_set_breaks_during_encode
m = NpeMessage.new(
# type: :Something, # doesn't have to be set
other: "foo" # must be set, but can be blank
)
begin
encoded = NpeMessage.encode(m)
rescue java.lang.NullPointerException
flunk "NPE rescued"
end
decoded = NpeMessage.decode(encoded)
decoded.inspect
decoded.to_proto
end
def test_type_enum_with_other_field_set_breaks_after_inspect
m = NpeMessage.new(
type: :Something, # can be set
other: "foo" # must be set, and cannot be blank
)
encoded = NpeMessage.encode(m)
decoded = NpeMessage.decode(encoded)
decoded.inspect
begin
decoded.to_proto
rescue java.lang.NullPointerException
flunk "NPE rescued"
end
end
def test_type_enum_with_other_field_not_set_works
m = NpeMessage.new(
type: :Something, # can be set
# other: "" # shouldn’t be set to demonstrate error
)
begin
encoded = NpeMessage.encode(m)
decoded = NpeMessage.decode(encoded)
decoded.inspect
decoded.to_proto
rescue java.lang.NullPointerException
flunk "NPE rescued"
end
end
def test_nontype_enum_with_other_field_works
m = WorkingNonTypeEnumMessage.new(
nontype: :Something,
other: "something else"
)
begin
encoded = WorkingNonTypeEnumMessage.encode(m)
decoded = WorkingNonTypeEnumMessage.decode(encoded)
decoded.inspect
decoded.to_proto
rescue java.lang.NullPointerException
flunk "NPE rescued"
end
end
def test_type_enum_without_other_field_works
m = WorkingTypeEnumMessage.new(
type: :Something
)
begin
encoded = WorkingTypeEnumMessage.encode(m)
decoded = WorkingTypeEnumMessage.decode(encoded)
decoded.inspect
decoded.to_proto
rescue java.lang.NullPointerException
flunk "NPE rescued"
end
end
def test_type_non_enum_with_other_field_works
m = WorkingTypeNonEnumMessage.new(
type: "something",
other: "something else"
)
begin
encoded = WorkingTypeNonEnumMessage.encode(m)
decoded = WorkingTypeNonEnumMessage.decode(encoded)
decoded.inspect
decoded.to_proto
rescue java.lang.NullPointerException
flunk "NPE rescued"
end
end
pool = Google::Protobuf::DescriptorPool.new
pool.build do
add_message "NpeMessage" do
optional :type, :enum, 1, "TestEnum"
optional :other, :string, 2
end
add_message "WorkingNonTypeEnumMessage" do
optional :nontype, :enum, 1, "TestEnum"
optional :other, :string, 2
end
add_message "WorkingTypeEnumMessage" do
optional :type, :enum, 1, "TestEnum"
end
add_message "WorkingTypeNonEnumMessage" do
optional :type, :string, 1
optional :other, :string, 2
end
add_enum "TestEnum" do
value :Something, 0
end
end
NpeMessage = pool.lookup("NpeMessage").msgclass
WorkingNonTypeEnumMessage = pool.lookup("WorkingNonTypeEnumMessage").msgclass
WorkingTypeEnumMessage = pool.lookup("WorkingTypeEnumMessage").msgclass
WorkingTypeNonEnumMessage = pool.lookup("WorkingTypeNonEnumMessage").msgclass
TestEnum = pool.lookup("TestEnum").enummodule
end We have narrowed the issue down to an enum named cc @ericksonb |
We've further confirmed that the issue is related to an enum named |
@NC-piercej - can you confirm that you're experiencing this issue under JRuby 9.3.3.0 but not under JRuby 9.2.x? |
@JasonLunn The issue seems to affect 9.2.x as well: |
Thanks so much for the fix, @JasonLunn! 🎉 😄 |
What version of protobuf and what language are you using?
Version: v3.19.4
Language: JRuby
What operating system (Linux, Windows, ...) and version?
Linux, official JRuby 9.3.3.0 docker image (
jruby:9.3.3.0-jre11
)What runtime / compiler are you using (e.g., python version or gcc version)
JRuby 9.3.3.0
What did you do?
This will work:
This will explode:
What did you expect to see
Instance converted to proto binary without an error.
What did you see instead?
Anything else we should know about your project / environment
Only some messages seem to have this issue. We also suspect that methods other than
inspect
may be able to trigger the issue.This seems to only occur when
decode
is used to build the message from a proto binary string. When the proto is built using the constructor from a hash, everything works fine.In general, the JRuby version has a ton of bugs relative to the CRuby version. Methods like
dup
plain do not work on the JRuby version (I may create a separate issue about this).The text was updated successfully, but these errors were encountered: