History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-2861
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: David Koontz
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JRuby

Cannot call super inside a method that overrides a protected method on Java base class

Created: 23/Jul/08 04:48 PM   Updated: 24/Jul/08 07:07 PM
Component/s: Java Integration
Affects Version/s: JRuby 1.1.3
Fix Version/s: None

Time Tracking:
Not Specified


 Description  « Hide
Currently, protected methods do not show up as visible methods on a Ruby subclass. Calling super inside an overriden protected method will yield the error: super: no superclass method `fooMethod'

The workaround is two fold. First you must get a reference to the superclass' method, then instead of calling super in your overriden method you call the method reference you got earlier.

public BaseFoo {
protected void doFoo(String s) { ... }
}

class Foo < Java::BaseFoo
def initialize
@do_foo_method = BaseFoo.java_class.declared_method("doFoo", java.lang.String)
@do_foo_method.accessible = true
end

def doFoo(s)
@do_foo_method.invoke(self.java_object, s.java_object)
#now you can do your method's logic here
end
end



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
David Koontz - 24/Jul/08 07:07 PM
A few things to note about the workaround.

1. You must call declared_method on the actual class the method is defined on. So if you have A < B, B < C and you're normally dealing with C but one of it's protected methods was actually declared on A you must use A.java_class.declared_method("someMethod", ... )

2. For primitive arguments use :int, :float, :boolean

FooClass.java_class.declared_method("primitiveMethod", :int, :int, :boolean)