Skip to content
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

Accessing repeated bytes field gives a TypeError using jruby #1820

Closed
DanilSerd opened this issue Jul 21, 2016 · 3 comments
Closed

Accessing repeated bytes field gives a TypeError using jruby #1820

DanilSerd opened this issue Jul 21, 2016 · 3 comments
Assignees
Labels

Comments

@DanilSerd
Copy link

This only happens if the message was encoded and then decoded.

Jruby version: jruby 1.7.25
protobuf version: protobuf-3.0.0-beta-4

This fails:

require 'google/protobuf'

Google::Protobuf::DescriptorPool.generated_pool.build do
  add_message "TestMessage" do
    repeated :repeated_bytes, :bytes, 1
  end

end

TestMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("TestMessage").msgclass

test_message = TestMessage.new(:repeated_bytes => ["hello".encode("ASCII-8BIT")])
reencoded_message = TestMessage.decode(TestMessage.encode(test_message))

reencoded_message.repeated_bytes[0]

Here's the TypeError:

TypeError: Encoding for bytes fields must be "ASCII-8BIT", but was UTF-8 push at com/google/protobuf/jruby/RubyRepeatedField.java:169 [] at com/google/protobuf/jruby/RubyMessage.java:136 method_missing at com/google/protobuf/jruby/RubyMessage.java:223 (root) at test.rb:19

Failure is on the last line. So it looks like it encodes and decodes the message just fine, but fails on access. Have also tested this with byte map fields, resulting in the same behaviour.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Jul 21, 2016

Does this error also happen if you use the ruby implementation?

@DanilSerd
Copy link
Author

@xfxyjwf No, it's not happening with ruby.

@haberman
Copy link
Member

I believe this is fixed in #7923.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants