You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ScriptingContainerc = newScriptingContainer();
c.runScriptlet("#this is script A\n" +
"puts Thread.current.to_s");
System.out.println("============================");
c.runScriptlet("#this is script B\n" +
"import java.lang.Thread\n" +
"puts 'hello'");
System.out.println("============================");
c.runScriptlet("#this is script C\n" +
"puts Thread.current.to_s");
Console output
#<Thread:0x5782ce4d>
============================
hello
============================
uri:classloader:/jruby/java/core_ext/object.rb:95: warning: already initialized constant Thread
NoMethodError: undefined method `current' for Java::JavaLang::Thread:Class
Did you mean? currentThread
method_missing at org/jruby/RubyBasicObject.java:1657
<main> at <script>:2
Exception in thread "main" org.jruby.embed.EvalFailedException: (NoMethodError) undefined method `current' for Java::JavaLang::Thread:Class
Did you mean? currentThread
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:131)
at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:1307)
at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1300)
at com.TestThread.main(TestThread.java:22)
Caused by: org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `current' for Java::JavaLang::Thread:Class
Did you mean? currentThread
at org.jruby.RubyBasicObject.method_missing(org/jruby/RubyBasicObject.java:1657)
at RUBY.<main>(<script>:2)
you import import java.lang.Thread Java's thread into default Object name-space
... so you end up aliasing Ruby's Thread to java.lang.Thread than there's no current in Java's world
the warnings/messages are pretty clear about it :
warning: already initialized constant Thread
undefined method `current' for Java::JavaLang::Thread
remove the import line and Thread.current will work as (Ruby) expected
Console output
Expected output
Environment
jruby-complete-9.1.15.0.jar
The text was updated successfully, but these errors were encountered: