Skip to content

Fixes #6242. Sorbet srb init crashes#6756

Merged
enebo merged 3 commits intojruby:masterfrom
enebo:srb_fix
Jul 29, 2021
Merged

Fixes #6242. Sorbet srb init crashes#6756
enebo merged 3 commits intojruby:masterfrom
enebo:srb_fix

Conversation

@enebo
Copy link
Member

@enebo enebo commented Jul 21, 2021

The fix here is to not register JavaPackage as a constant of Java.
This prevents srb from finding it via constants. So the problem class
is never seen.

Note: I think in the scenario of walking ObjectSpace we can still run
across this but that may be another issue to deal with when we experience it.

The explanation of what is wrong is that JavaPackage is in fact a Class but
due to how we want it to behave we set its metaclass to Module. When srb
retrieves an UnboundMethod off of Class that method cannot be bound to this
type because it says "nope I am a module" (even though it is actually a class).

The fix here is to not register JavaPackage as a constant of Java.
This prevents srb from finding it via constants.  So the problem class
is never seen.

Note: I think in the scenario of walking ObjectSpace we can still run
across this but that may be another issue to deal with when we experience it.

The explanation of what is wrong is that JavaPackage is in fact a Class but
due to how we want it to behave we set its metaclass to Module.  When srb
retrieves an UnboundMethod off of Class that method cannot be bound to this
type because it says "nope I am a module" (even though it is actually a class).
@enebo enebo added this to the JRuby 9.3.0.0 milestone Jul 21, 2021
@enebo enebo requested a review from kares July 21, 2021 17:37
@enebo
Copy link
Member Author

enebo commented Jul 21, 2021

@kares I think one big decision here is that Java::JavaPackage is no longer something we would care about seeing within Ruby code. This makes some of my test changes in the higher level tests suspect. It also makes JavaPackage even weirder because it thinks it exists but we have no simple way within Ruby to get an instance of it.

@enebo enebo requested a review from headius July 21, 2021 19:18
Copy link
Member

@kares kares left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tried to find anything on GH but seems JRuby was the only user of Java::JavaPackage.

if someone comes around we should consider having a blessed API to check for something being a Java package e.g. JRuby.java_package?(some_type) ... hopefully no one needs that 😉


public abstract RubyClass getJavaPackageClass() ;
public abstract RubyClass getJavaPackageClass();
public abstract void setJavaPackageClass(RubyClass javaPackageClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should work if it's package private - not really public API

Suggested change
public abstract void setJavaPackageClass(RubyClass javaPackageClass);
abstract void setJavaPackageClass(RubyClass javaPackageClass);

@headius
Copy link
Member

headius commented Jul 26, 2021

Simple fix is best fix... ship it!

@enebo enebo merged commit feb8fa4 into jruby:master Jul 29, 2021
@enebo enebo deleted the srb_fix branch March 4, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants