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

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

Merged
merged 1 commit into from
Apr 27, 2016
Merged

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

merged 1 commit into from
Apr 27, 2016

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.

None yet

2 participants