Newly overridden methods are not called if the old superclass method has
already been called
--------------------------------------------------------------------------------------------
Key: JRUBY-2921
URL: http://jira.codehaus.org/browse/JRUBY-2921
Project: JRuby
Issue Type: Bug
Components: Core Classes/Modules
Affects Versions: JRuby 1.1.3
Environment: Demonstrated on Windows, with jruby 1.1.3 (ruby 1.8.6
patchlevel 114) (2008-07-20 rev 7243) [x86-java]
Reporter: Peter Olsen
A subclass method that overrides a superclass method is inconsistently called.
In the code sample below, JRuby does not call the subclass's meth1, but does
call the subclass's meth2. The difference is whether or not the superclass's
meth1 was previously called by another method (calling_meth1). MRI Ruby always
calls the subclass's method.
A consequence of this bug is that Mocha 0.9.0 works inconsistently with JRuby.
Mocha 0.5.6, unlike 0.9.0, undefines the superclass's method, so it works OK.
But 0.9.0 mocked methods will not be called if the unmocked method has already
been called, even if that was in a different test case. This means the order in
which test cases run changes the results of the tests.
{noformat}
def calling_meth1
MySub.meth1
end
def calling_meth2
MySub.meth2
end
class MySuper
def self.meth1
puts 'MySuper::meth1'
end
def self.meth2
puts 'MySuper::meth2'
end
end
class MySub < MySuper
end
puts "# of meth1s = #{MySub.methods.select {|m| m == 'meth1'}.size }"
puts "# of meth2s = #{MySub.methods.select {|m| m == 'meth2'}.size }"
puts 'The following lines should call MySuper methods'
MySub::meth1
calling_meth1
MySub::meth2
puts 'Note: calling_meth2 is not called here'
class MySub
def self.meth1
puts 'MySub::meth1'
end
def self.meth2
puts 'MySub::meth2'
end
end
puts "# of meth1s = #{MySub.methods.select {|m| m == 'meth1'}.size }" # JRuby
prints 2, but MRI Ruby prints 1
puts "# of meth2s = #{MySub.methods.select {|m| m == 'meth2'}.size }"
puts 'The following lines should call MySub methods'
MySub::meth1
calling_meth1 # JRuby prints MySuper::meth1 here, but MRI Ruby prints
MySub::meth1
MySub::meth2
calling_meth2
{noformat}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
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