File tree Expand file tree Collapse file tree 3 files changed +20
-9
lines changed
core/src/main/java/org/jruby
spec/java_integration/extensions Expand file tree Collapse file tree 3 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -2471,7 +2471,13 @@ private String identityString() {
24712471 */
24722472 @ Override
24732473 public <T > T toJava (final Class <T > target ) {
2474- // since 9.4 the default toJava(java.lang.Object.class) is formalized to return a Java thread
2474+ // since 9.4 due compatibility with JRuby <= 9.3, hopefully to be removed in 9.5
2475+ if (target == Object .class ) {
2476+ // NOTE: a deprecation wasn't introduced in 9.4 simply due the need to cleanup libraries first and their
2477+ // Thread.current.to_java.getNativeThread/getContext usage, in 9.5 a deprecation should be added here
2478+ return super .toJava (target ); // simply returns the (internal) org.jruby.RubyThread
2479+ }
2480+
24752481 if (target .isAssignableFrom (Thread .class )) { // Thread | Runnable | Object
24762482 return target .cast (getNativeThread ());
24772483 }
Original file line number Diff line number Diff line change 44
55 context 'RubyThread' do
66
7- it 'is (default) convertible to a java thread' do
8- expect ( Thread . current . to_java ) . to be_a java . lang . Thread
9- expect ( Thread . current . to_java ) . to be java . lang . Thread . currentThread
7+ it 'maintains compatibility with <= 9.3 when doing a default to_java conversion (till 9.6)' do
8+ if JRUBY_VERSION < '9.6'
9+ expect ( Thread . current . to_java ) . to be_a org . jruby . RubyThread
10+ else
11+ # NOTE: a naive attempt to get this looked into in 9.6 and channge the Thread#to_java default
12+ expect ( Thread . current . to_java ) . to be_a java . lang . Thread
13+ expect ( Thread . current . to_java ( java . lang . Object ) ) . to be java . lang . Thread . currentThread
14+ end
1015 end
1116
1217 it 'is explicitly convertible to a java thread' do
1318 thread = Thread . start { sleep 1.0 }
1419 expect ( thread . to_java ( java . lang . Thread ) ) . to be_a java . lang . Thread
15- expect ( thread . to_java ( 'java.lang.Object ' ) ) . to be_a java . lang . Thread
20+ expect ( thread . to_java ( 'java.lang.Runnable ' ) ) . to be_a java . lang . Thread
1621 end
1722
1823 it 'can be converted to internal JRuby class' do
Original file line number Diff line number Diff line change @@ -365,7 +365,6 @@ def test_inspect_and_to_s
365365 end
366366
367367 def test_thread_name
368- pend 'java.lang.Thread.native_thread is not implemented'
369368 Thread . new do
370369 assert_match ( /\# \< Thread\: 0x\h +( ([A-Z]:)?[\w \/ \. \- _]+\: \d +)?\s run\> / , Thread . current . inspect )
371370 end . join
@@ -384,15 +383,16 @@ def test_thread_name
384383
385384 Thread . new do
386385 my_name = 'user-set-native-thread-name'
387- Thread . current . to_java . native_thread . name = my_name
386+ java_thread = java . lang . Thread . currentThread
387+ java_thread . setName ( my_name )
388388 Thread . current . name = 'foo'
389389
390390 assert Thread . current . inspect . index ( '@foo' )
391- assert_equal my_name , Thread . current . to_java . native_thread . name
391+ assert_equal my_name , java_thread . getName
392392
393393 Thread . current . name = nil
394394 assert ! Thread . current . inspect . index ( '@foo' )
395- assert_equal my_name , Thread . current . to_java . native_thread . name
395+ assert_equal my_name , java . lang . Thread . currentThread . getName
396396 end . join
397397 end
398398
You can’t perform that action at this time.
0 commit comments