Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6f98597dcf67
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ba15f3e13125
Choose a head ref
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Apr 27, 2016

  1. 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.
    yuki24 committed Apr 27, 2016
    Copy the full SHA
    238e83f View commit details
  2. Merge pull request #3832 from yuki24/fix-nameerror-receiver

    Fix a bug where NameError#receiver raises an ArgumentError after #to_s is called
    headius committed Apr 27, 2016
    Copy the full SHA
    ba15f3e View commit details
Showing with 4 additions and 2 deletions.
  1. +4 −2 core/src/main/java/org/jruby/RubyNameError.java
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyNameError.java
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
@JRubyClass(name="NameError", parent="StandardError")
public class RubyNameError extends RubyException {
private IRubyObject name;
private IRubyObject receiver;

/**
* Nested class whose instances act as thunks reacting to to_str method
@@ -207,6 +208,7 @@ static RubyException newNameError(IRubyObject recv, IRubyObject message, IRubyOb
@Override
public IRubyObject initialize(IRubyObject[] args, Block block) {
if ( args.length > 0 ) this.message = args[0];
if (message instanceof RubyNameErrorMessage) this.receiver = ((RubyNameErrorMessage) message).object;
if ( args.length > 1 ) this.name = args[1];
else this.name = getRuntime().getNil();
super.initialize(NULL_ARRAY, block); // message already set
@@ -231,8 +233,8 @@ public IRubyObject name() {

@JRubyMethod
public IRubyObject receiver(ThreadContext context) {
if (message instanceof RubyNameErrorMessage) {
return ((RubyNameErrorMessage) message).object;
if (receiver != null) {
return receiver;
}

throw context.runtime.newArgumentError("no receiver is available");