nick created Bug JRUBY-6885
Issue Type: Bug Bug
Affects Versions: JRuby 1.7.0.pre2
Assignee: Thomas E Enebo
Created: 11/Sep/12 1:49 AM
Description:

There seems to be an issue with a combination of public_send() (or send()) and
method_missing() when trying to call a method named "warn". The issue appears
with JRuby, but not when running the same code in Ruby from the command line.

First, the test case:

JUnit Test Case

@Test
public void shouldRunFine() {


ScriptingContainer container = new ScriptingContainer();

container.runScriptlet(

"class Me \n" +
"def method_missing(method_name, *args, &block) \n" +
"puts \"you have called: #{method_name}\" \n" +
"end \n" +
"end \n" +

"m = Me.new \n" +
"m.public_send(:info) \n" +
"m.public_send(:blah) \n" +

"# problem happens just here: \n" +
"m.public_send(:warn) \n"
);
}
{/code}

As above the code throws an exception on last line, output:

------------- Standard Output ---------------
you have called: info
you have called: blah
------------- ---------------- ---------------
------------- Standard Error -----------------
NoMethodError: private method `warn' called for Me:Class
  public_send at org/jruby/RubyKernel.java:1784
       (root) at <script>:10
------------- ---------------- ---------------
Testcase: shouldRunFine(org.magnepath.general.RubyCallerTest):  Caused an ERROR
(NoMethodError) private method `warn' called for Me:Class
org.jruby.embed.EvalFailedException: (NoMethodError) private method `warn' called for Me:Class
    at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:133)
    at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1264)
    at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1257)
    at org.magnepath.general.RubyCallerTest.shouldRunFine(RubyCallerTest.java:80)
Caused by: org.jruby.exceptions.RaiseException: (NoMethodError) private method `warn' called for Me:Class
    at org.jruby.RubyKernel.public_send(org/jruby/RubyKernel.java:1784)
    at RUBY.(root)(<script>:10)
{/noformat}

The failure happens on script line 10, which is the attempted call to "warn".
The other invovations of public_send() work as expected.

If I change the final line to use "send(:warn)" instead of public_send(), I get:


------------- Standard Output ---------------
you have called: info
you have called: blah
------------- ---------------- ---------------
------------- Standard Error -----------------
ArgumentError: wrong number of arguments calling `warn` (0 for 1)
_send_ at org/jruby/RubyBasicObject.java:1667
send at org/jruby/RubyKernel.java:2060
(root) at <script>:10
------------- ---------------- ---------------
Testcase: shouldRunFine(org.magnepath.general.RubyCallerTest): Caused an ERROR
(ArgumentError) wrong number of arguments calling `warn` (0 for 1)
org.jruby.embed.EvalFailedException: (ArgumentError) wrong number of arguments calling `warn` (0 for 1)
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:133)
at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1264)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1257)
at org.magnepath.general.RubyCallerTest.shouldRunFine(RubyCallerTest.java:80)
Caused by: org.jruby.exceptions.RaiseException: (ArgumentError) wrong number of arguments calling `warn` (0 for 1)
at org.jruby.RubyBasicObject._send_(org/jruby/RubyBasicObject.java:1667)
at org.jruby.RubyKernel.send(org/jruby/RubyKernel.java:2060)
at RUBY.(root)(<script>:10)
{/noformat}

which seems to suggest their is a private :warn method on Class with 1 argument?

Meanwhile, if I run the equivalent code as below



class Me
def method_missing(method_name, *args, &block)
puts "you have called: #{method_name}"
end
end

m = Me.new
m.public_send(:info)
m.public_send(:blah)
m.public_send(:warn)

{/noformat}

against Ruby on the command-line, I get the following output with no errors:



you have called: info
you have called: blah
you have called: warn{/noformat}

The version of ruby installed on my system is:


ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]

{/noformat}
Environment: MacOS 10.7.3, Netbeans 7.2
Project: JRuby
Priority: Major Major
Reporter: nick
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to