In #7549 we added the ability to call Thread.to_java(java.lang.Thread) to get the native Java thread associated with a Ruby thread. However we also attempted to make the default to_java() behavior return java.lang.Thread instead of the org.jruby.RubyThread it has historically returned.
This default change would unfortunately break code in the wild that uses the to_java.native_thread pattern, such as these examples found by @kares:
There's also at least one case of to_java.getContext in the wild, further exposing RubyThread internals:
We will want to help patch these and other cases to use:
to_java(java.lang.Thread) instead of to_java.native_thread
java.lang.Thread.current_thread instead of Thread.current.to_java.native_thread
to_java(org.jruby.RubyThread for remaining cases that actually need access to RubyThread (or provide blessed alternatives to those methods, like JRuby.context
JRuby 9.4 will continue to return RubyThread from the default to_java(), with deprecation of that form coming in "9.5" and eventually changing the default return value to java.lang.Thread in "9.6"
In #7549 we added the ability to call
Thread.to_java(java.lang.Thread)to get the native Java thread associated with a Ruby thread. However we also attempted to make the defaultto_java()behavior returnjava.lang.Threadinstead of theorg.jruby.RubyThreadit has historically returned.This default change would unfortunately break code in the wild that uses the
to_java.native_threadpattern, such as these examples found by @kares:There's also at least one case of
to_java.getContextin the wild, further exposing RubyThread internals:We will want to help patch these and other cases to use:
to_java(java.lang.Thread)instead ofto_java.native_threadjava.lang.Thread.current_threadinstead ofThread.current.to_java.native_threadto_java(org.jruby.RubyThreadfor remaining cases that actually need access to RubyThread (or provide blessed alternatives to those methods, likeJRuby.contextJRuby 9.4 will continue to return RubyThread from the default
to_java(), with deprecation of that form coming in "9.5" and eventually changing the default return value to java.lang.Thread in "9.6"