Generify IRubyObject.toJava to make it more pleasant to use. #5063
This change allow callers to skip the cast when calling toJava
I tested binary compatibility in two ways:
Of course any external JRuby extensions (readline, openssl) will
This change allow callers to skip the cast when calling toJava on a Ruby object. It was initially done to assist work on #4781 by allowing a simple "throw rubyException.toJava(Throwable.class). I tested binary compatibility in two ways: * A full recompile with all generification in place plus testing standard JRuby commands. This confirms that classes recompiled against the API but without other use of generics still function properly. * A partial recompile with only the generified classes rebuilt. This tests that classes not compiled against the API still function properly. Of course any external JRuby extensions (readline, openssl) will have been tested by running those standard commands (e.g. irb, gem install).
Bit of a snag...it appears that Class.cast does not work when the desired target is a primitive. This is noted in the toJava for RubyBoolean, since that logic wants to return a boolean but you can't return or cast to boolean from a generified method.
This may not have a generic fix since there does not appear to be any way to programmatically cast primitives.
I have additional fixes and no longer believe the casting issue is a big problem.
After inspecting all our toJava implementations, only a handful can toJava into primitive types. Those cases will be fixed to just do manual casting to the container type.
The generic toJava in JavaProxy could be a problem, but it does not appear to break even when specifying primitive target types for a boxed numeric, probably because it doesn't really coerce to a different type:
This may constitute a bug and get fixed at some point, so I'll make sure the blind casting here is at least smart about primitives.