Skip to content

Fix a bug where NameError#receiver raises an ArgumentError after #to_s is called#3832

Merged
headius merged 1 commit intojruby:masterfrom
yuki24:fix-nameerror-receiver
Apr 27, 2016
Merged

Fix a bug where NameError#receiver raises an ArgumentError after #to_s is called#3832
headius merged 1 commit intojruby:masterfrom
yuki24:fix-nameerror-receiver

Conversation

@yuki24
Copy link
Contributor

@yuki24 yuki24 commented Apr 27, 2016

If the NameError#to_s is called before NameError#receiver is called, the NameError object will lose the source of the receiver object and the NameError#receiver method will raise an ArgumentError when it shouldn't:

error = (1.foo rescue $!)
error.receiver # => 1
error.to_s     # => NameError: ... <= This call replaces the internal `message` object
error.receiver # => ArgumentError: no receiver is available

This commit changes the initializer to retrieve the receiver object so that the behavior of the method will be consistent.

…s is called

If the `NameError#to_s` is called before `NameError#receiver` is called, the NameError object will lose the source of the receiver object (https://github.com/jruby/jruby/blob/b856557/core/src/main/java/org/jruby/RubyNameError.java#L223) and the `NameError#receiver` method will raise an ArgumentError when it shouldn't.

error = (1.foo rescue $!)
error.receiver # => 1
error.to_s     # => NameError: ... <= This call replaces the `message` object
error.receiver # => ArgumentError: no receiver is available

This commit changes the initializer to retrieve the receiver object so that the behavior of the method will be consistent.
@headius
Copy link
Member

headius commented Apr 27, 2016

Nice find, thank you!

@headius headius merged commit ba15f3e into jruby:master Apr 27, 2016
@headius headius added this to the JRuby 9.1.0.0 milestone Apr 27, 2016
@yuki24 yuki24 deleted the fix-nameerror-receiver branch April 27, 2016 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants