Skip to content

Marshal.load fails to unmarshal OpenStruct object #6662

@mojavelinux

Description

@mojavelinux

Environment Information

JRuby version string:

jruby 9.3.0.0-SNAPSHOT (2.6.5) 2021-04-28 a309a88614 OpenJDK 64-Bit Server VM 11.0.10+9 on 11.0.10+9 +jit [linux-x86_64]

Operating system:

Linux 5.11.15-200.fc33.x86_64

Expected Behavior

The following script should succeed:

require 'ostruct'
data = { foo: 'bar' }
::Marshal.load ::Marshal.dump ::OpenStruct.new data

Actual Behavior

An exception is thrown:

NoMethodError: undefined method `key?' for nil:NilClass
  new_ostruct_member! at /home/dallen/.rvm/rubies/jruby-head/lib/ruby/stdlib/ostruct.rb:226
         marshal_load at /home/dallen/.rvm/rubies/jruby-head/lib/ruby/stdlib/ostruct.rb:216
             each_key at org/jruby/RubyHash.java:1558
         marshal_load at /home/dallen/.rvm/rubies/jruby-head/lib/ruby/stdlib/ostruct.rb:216
                 load at org/jruby/RubyMarshal.java:138

It appears that the @table instance variable is not initialized when marshal_load is called in jruby-head/lib/ruby/stdlib/ostruct.rb. As a result, the call @table.key? fails.

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