jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-2921

Newly overridden methods are not called if the old superclass method has already been called

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1.3
  • Fix Version/s: JRuby 1.2
  • Component/s: Core Classes/Modules
  • Labels:
    None
  • Environment:
    Demonstrated on Windows, with jruby 1.1.3 (ruby 1.8.6 patchlevel 114) (2008-07-20 rev 7243) [x86-java]

Description

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.

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

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Charles Oliver Nutter added a comment - 08/Feb/09 4:30 PM

We fixed this some time ago by reworking our call site caching to invalidate based on changes anywhere in the hierarchy. But I also fixed the duplicate methods issue and formed your script into a test case. All committed in r9068.

Show
Charles Oliver Nutter added a comment - 08/Feb/09 4:30 PM We fixed this some time ago by reworking our call site caching to invalidate based on changes anywhere in the hierarchy. But I also fixed the duplicate methods issue and formed your script into a test case. All committed in r9068.

People

  • Assignee:
    Charles Oliver Nutter
    Reporter:
    Peter Olsen
Vote (0)
Watch (1)

Dates

  • Created:
    14/Aug/08 8:00 AM
    Updated:
    21/Mar/09 1:14 PM
    Resolved:
    08/Feb/09 4:30 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.