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
Passing self
to java code from ctor in a class that extends a java class causes NPE
#6140
Comments
This might not be possible to fix. At the point where you're calling Because we can't "really" extend a Java class from Ruby (because all Ruby objects must extend RubyBasicObject, and can't extend another Java class as well) the lifecycle of this case has some inherent challenges. If we construct the Java object first and then initialize the Ruby object, the Java object will not be able to see a constructed Ruby object. If we initialize the Ruby object first (which is how we do it now), the Java object won't be available. In JRuby, we opted to construct the Ruby object first, since it's at the bottom (it represents the subclass) and because it allows the Ruby initialize to decide how to construct the superclass object (via the super call). We could perhaps make a better error here... something along the lines of "uninitialized subclass object, please invoke `super' first". I'm not sure there's a way to make this work, though. Thoughts, @enebo? BTW, what outputs this reversed trace? I never implemented reversed backtraces in JRuby! |
That's fine, I just don't think we want raw NPE's bouncing around, hence the filing
IRB, as installed via rvm for jruby-9.2.7.0 |
I don't know if this was obvious from @headius reply but if you add super before that self reference this does not crash. This seemingly is a workaround for you at least. The bulk of the problem is Ruby is a language of values. If we knew the value came from the keyword self as the holder then this would be simple. Of course, we could add that to our runtime but it would penalize all code. @headius I believe we discussed implicit super in JI initialize when none is present? I don't recall the issues (I can guess picking zsuper vs super() as one) but implicit addition would eliminate the error if we could. |
@enebo thanks, yes, I figured out the workaround before I filed, though probably should have mentioned that |
Perhaps we should revisit having a hard error if you don't call |
At the very least I think we can make it a hard error if |
Environment Information
Provide at least:
Expected Behavior
Should not do anything observable
Actual Behavior
The text was updated successfully, but these errors were encountered: