Fixes #6242. Sorbet srb init crashes#6756
Conversation
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).
|
@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. |
kares
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
should work if it's package private - not really public API
| public abstract void setJavaPackageClass(RubyClass javaPackageClass); | |
| abstract void setJavaPackageClass(RubyClass javaPackageClass); |
|
Simple fix is best fix... ship it! |
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).