Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `current' for Java::JavaLang::Thread:Class #4901

Closed
javalovercn opened this issue Dec 17, 2017 · 2 comments
Closed

Comments

@javalovercn
Copy link

ScriptingContainer c = new ScriptingContainer();

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 Thread.getAllStackTraces().size().to_s# invoke java Thread\n");

System.out.println("============================");

c.runScriptlet("" +
		"#this is script C\n" +
		"puts Thread.current.to_s");

we can't remove "import java.lang.Thread" because user is required to access java Thread.
if change jruby-complete-9.1.15.0.jar to jruby-complete-1.7.3.jar, it works well.

Console output

#<Thread:0x6b95c03e>
============================
uri:classloader:/jruby/java/core_ext/object.rb:95: warning: already initialized constant Thread
4
============================
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)

Expected output

#<Thread:0x6b95c03e>
============================
4
============================
#<Thread:0x6b95c03e>

Environment

jruby-complete-9.1.15.0.jar

@mkristian
Copy link
Member

you should just use the qualified classname: java.lang.Thread.getAllStackTraces().size().to_s or alias the java Thread class with JThread = java.lang.Thread and use JThread where needed.

not a bug for me.

@kares
Copy link
Member

kares commented Dec 17, 2017

Kristian is right, this is a 'known' JRuby feature.
you need to be careful when importing colliding Java classes e.g. String or Thread

@kares kares closed this as completed Dec 17, 2017
@kares kares added this to the Invalid or Duplicate milestone Dec 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants