Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JRuby returns an instance of Java superclass instead of a Ruby subclass #2609

Open
mebe opened this issue Feb 19, 2015 · 5 comments
Open

JRuby returns an instance of Java superclass instead of a Ruby subclass #2609

mebe opened this issue Feb 19, 2015 · 5 comments

Comments

@mebe
Copy link

@mebe mebe commented Feb 19, 2015

This bug has quite many moving parts. I've tried to summarize them below. Hopefully the included code example makes the case clearer.

Reproducing this bug requires the following:

  • A: Java class that has been reopened in Ruby where an inherited hook has been added
  • B: Ruby subclass of A
  • C: Java interface that defines one method that returns A
  • D: Ruby implementation of C that creates an instance of B as its return value
  • E: Another Java method that accepts an implementation of C and calls its method

When D is passed to E, A is returned instead of B. If the inherited hook is removed from A, then B is returned as expected.

If the object proxy cache is enabled, the code works "most of the time." A is still returned instead of B "randomly." This bug was originally reported by my colleague back in 2011: ago: http://jira.codehaus.org/browse/JRUBY-6151

I've tried to make a minimal test case that includes both the broken inherited implementation as well as a class that has no inherited and works as expected.

Code: https://github.com/mebe/JRubyNoWrapping

@headius
Copy link
Member

@headius headius commented Mar 12, 2015

Your hooks are very likely causing some trouble for the class-extension logic in JRuby. It's very sensitive to the sequence of events that happen during class definition.

Thank you for the reproduction, though! That will help us sort out if something can be done to repair this.

@headius
Copy link
Member

@headius headius commented Mar 12, 2015

Copy @kares since he has been poking around JI recently.

@kares
Copy link
Member

@kares kares commented May 27, 2015

turns out JI depends on super's inherited being called, otherwise Java sub-classes might not work correctly. this is fine when inherited is not overriden (as the test confirms) in the Ruby sub-class but fails otherwise. work-around for now is to call super in the inherited callback.

@headius I'm thinking of creating a thin internal RubyClass sub-class ProxyClass.java ... that would solve the need for relying on inherited called from Ruby-land. I think it might be useful for the future to have a ProxyModule (for proxied interfaces) as well to eaze the pain of hooking up these. let me know if you can think of any reason not to. I'm hoping to test the ProxyClass out soon-ish

@enebo
Copy link
Member

@enebo enebo commented May 16, 2017

@kares this is also a problem on 9.x right?

@kares
Copy link
Member

@kares kares commented May 16, 2017

yes probably still is, will re-check (hopefully I get into some JI work that's on my todo/cleanup stack for 9.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants