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

Conversation

Projects
None yet
2 participants
@yuki24
Contributor

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.

Fix a bug where NameError#receiver raises an ArgumentError after #to_…
…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

This comment has been minimized.

Show comment
Hide comment
@headius

headius Apr 27, 2016

Member

Nice find, thank you!

Member

headius commented Apr 27, 2016

Nice find, thank you!

@headius headius merged commit ba15f3e into jruby:master Apr 27, 2016

0 of 2 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details

@headius headius added this to the JRuby 9.1.0.0 milestone Apr 27, 2016

@yuki24 yuki24 deleted the yuki24:fix-nameerror-receiver branch Apr 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment