Skip to content

NoMethodError: undefined method `[]' for <ClassName>:Class #6225

@mogman1

Description

@mogman1

I've created a test script with some specs to demonstrate this bug at https://github.com/mogman1/protobuf_error_script.

  • Jruby versions: >= 9.2.7.0
  • ActiveSupport 5.0 and 5.1, but NOT 4.2 or 5.2 or 6.0
  • protobuf (v3.10.3)
  • OSX and Ubuntu Xenial (see travis builds), probably others

The issue is that when attempting to check the value of a protobuf message attribute's truthiness by appending ? to the end of it (e.g. x.is_working?), for certain versions of JRuby and ActiveSupport 5, you get something like NoMethodError: undefined method `[]' for FailingProtobufMessage:Class. When the bug is occurring, the protobuf library is checking the class and not the instance itself when it calls self (see https://github.com/ruby-protobuf/protobuf/blob/v3.10.3/lib/protobuf/field/base_field.rb#L354 and error in Travis build). This does not happen on any MRI >= 2.4 or JRuby <= 9.2.6.0.

I was able to pinpoint the exact commit where this started happening as at 3a56fcb. Everything before that my tests will all pass, and then everything from then on I get the error I mentioned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions