-
-
Notifications
You must be signed in to change notification settings - Fork 939
Description
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:
- celluloid to_java.getNativeThread [jruby] do not rely on JRuby's Thread internals celluloid/celluloid#818
- sigdump to_java.getNativeThread be explicit about using JRuby Thread internals fluent/sigdump#17
There's also at least one case of to_java.getContext in the wild, further exposing RubyThread internals:
- method_source to_java.getContext [jruby] avoid Thread#to_java internals banister/method_source#79 (banister/method_source@1ce52b3)
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.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"