JRuby

Array#pack('w') is broken (exceptions and wrong results)

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1.2
  • Fix Version/s: JRuby 1.2
  • Component/s: Core Classes/Modules
  • Labels:
    None
  • Environment:
    Windows XP, JRuby 1.1.3, Java 1.6
  • Number of attachments :
    0

Description

Two Array#pack failures from ruby_test:

assert_raises(TypeError){ [nil].pack("w") }
assert_raises(TypeError){ ['a'].pack("w") }

Both raise a TypeError in MRI. In JRuby 1.1.3 the first returns "\000", while the second causes a NumberFormatException.

Activity

Hide
Vladimir Sizikov added a comment -

Indeedy. I also found a couple of more cases where JRuby is incorrect or crashes with pack('w'). All of this is added to the rubyspecs:

http://github.com/rubyspec/rubyspec/commit/d364f2b61ab39b8c0ba12d6171dc041895aacfaa

Show
Vladimir Sizikov added a comment - Indeedy. I also found a couple of more cases where JRuby is incorrect or crashes with pack('w'). All of this is added to the rubyspecs: http://github.com/rubyspec/rubyspec/commit/d364f2b61ab39b8c0ba12d6171dc041895aacfaa
Hide
Charles Oliver Nutter added a comment -

Another case recently added:

  it "checks whether the pack argument responds to #to_int" do
    obj = mock("method_missing to_int")
    obj.should_receive(:respond_to?).with(:to_int).any_number_of_times.and_return(true)
    obj.should_receive(:method_missing).with(:to_int).and_return(1)
    [obj].pack('w').should == binary("\001")
  end
Show
Charles Oliver Nutter added a comment - Another case recently added:
  it "checks whether the pack argument responds to #to_int" do
    obj = mock("method_missing to_int")
    obj.should_receive(:respond_to?).with(:to_int).any_number_of_times.and_return(true)
    obj.should_receive(:method_missing).with(:to_int).and_return(1)
    [obj].pack('w').should == binary("\001")
  end
Hide
Charles Oliver Nutter added a comment -

And this one also blows up:

  it "just ignores unknown format" do
    lambda{ [].pack("2") }.should_not raise_error
    lambda{ [].pack("J") }.should_not raise_error
    lambda{ [].pack("\xFF") }.should_not raise_error
    ["abc", "def"].pack("A\x7EA").should == "ad"
  end
Show
Charles Oliver Nutter added a comment - And this one also blows up:
  it "just ignores unknown format" do
    lambda{ [].pack("2") }.should_not raise_error
    lambda{ [].pack("J") }.should_not raise_error
    lambda{ [].pack("\xFF") }.should_not raise_error
    ["abc", "def"].pack("A\x7EA").should == "ad"
  end
Hide
Charles Oliver Nutter added a comment -

Resolved by fixes for JRUBY-3274.

Show
Charles Oliver Nutter added a comment - Resolved by fixes for JRUBY-3274.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: