Skip to content

Deprecate Thread#to_java returning RubyThread #7568

@headius

Description

@headius

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions