scijava/scripting-jruby

JRuby, "NoMethodError: undefined method `current' for Java::JavaLang::Thread:Class"

Closed this issue · 3 comments

Not sure if this is the right place to raise this issue as titled, but here you go.

The line causing this error is within jruby-stdlib-1.7.12.jar, at /META-INF/jruby.home/lib/ruby/1.9/monitor.rb:245
. It seems that:

I suspect some code somewhere is importing java.lang.Thread into a top-level namespace (like Object) and as a result overwriting the Ruby "Thread" class.

...accoding to https://www.ruby-forum.com/topic/2920464

By the way, I am not using JRuby so please do not feel this as my urgent request. I tested JRuby after Curtis introduced shading for the multiple version jffi problem. Jython is working well.

Below are the symptoms.


Test 1. Script Editor, one line of code.

Following one line works.

"hello there".upcase[1..4]

Test 2. Script Editor, with automatically inserted lines when "Ruby" is selected as language.

# @AppService appService
require_relative "#{$appService.getApp.getBaseDirectory}/plugins/JRuby/imagej.rb"

This causes the error, see below.

Started New_.rb at Thu Sep 11 11:38:10 CEST 2014
NoMethodError: undefined method `current' for Java::JavaLang::Thread:Class
   mon_check_owner at file:/Applications/Fiji.app/jars/jruby-stdlib-1.7.12.jar!/META-INF/jruby.home/lib/ruby/1.9/monitor.rb:245
          mon_exit at file:/Applications/Fiji.app/jars/jruby-stdlib-1.7.12.jar!/META-INF/jruby.home/lib/ruby/1.9/monitor.rb:195
           require at file:/Applications/Fiji.app/jars/jruby-stdlib-1.7.12.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:143
  require_relative at file:/Applications/Fiji.app/jars/jruby-core-1.7.12.jar!/jruby/kernel19/kernel.rb:21
            (root) at New_.rb:2
org.jruby.embed.EvalFailedException: (NoMethodError) undefined method `current' for Java::JavaLang::Thread:Class
    at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:133)
    at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:118)
    at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:146)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:175)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
    at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:164)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:695)
Caused by: org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `current' for Java::JavaLang::Thread:Class
    at RUBY.mon_check_owner(file:/Applications/Fiji.app/jars/jruby-stdlib-1.7.12.jar!/META-INF/jruby.home/lib/ruby/1.9/monitor.rb:245)
    at RUBY.mon_exit(file:/Applications/Fiji.app/jars/jruby-stdlib-1.7.12.jar!/META-INF/jruby.home/lib/ruby/1.9/monitor.rb:195)
    at RUBY.require(file:/Applications/Fiji.app/jars/jruby-stdlib-1.7.12.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:143)
    at RUBY.require_relative(file:/Applications/Fiji.app/jars/jruby-core-1.7.12.jar!/jruby/kernel19/kernel.rb:21)
    at RUBY.(root)(New_.rb:2)

@CMCI This is a perfect place to report this issue. Thanks for the detailed report & research.

In your Test 2 what was the script that was being executed? I couldn't reproduce the error you pasted.

Also would you mind pasting your system info here? (e.g., copy and past the contents of the "Useful information about your system" box from the Help > Report a Bug dialog)

Hi @hinerm ,

Thanks for your reply.

In your Test 2 what was the script that was being executed?

I did not write anything, just executed two lines I mentioned above.

When I launch JRuby Interpreter, I see similar class name conflict:

(Fiji Is Just) ImageJ 2.0.0-rc-14/1.49g; Java 1.6.0_65 [64-bit]; Mac OS X 10.8.5; 78MB of 16066MB (<1%)

org.jruby.exceptions.RaiseException: (ArgumentError) invalid Java class or interface: java.lang.Object
    at Object.java_import(file:/Applications/Fiji.app/jars/jruby-core-1.7.12.jar!/jruby/java/core_ext/object.rb:34)
    at org.jruby.RubyArray.map(org/jruby/RubyArray.java:2409)
    at Object.java_import(file:/Applications/Fiji.app/jars/jruby-core-1.7.12.jar!/jruby/java/core_ext/object.rb:22)
    at Object.include_class(file:/Applications/Fiji.app/jars/jruby-core-1.7.12.jar!/jruby/java/core_ext/object.rb:8)
    at RUBY.(root)(<script>:633)

Here is the system report.

Information about your version of Java:

  os.arch => x86_64
  os.name => Mac OS X
  os.version => 10.8.5
  java.version => 1.6.0_65
  java.vendor => Apple Inc.
  java.runtime.name => Java(TM) SE Runtime Environment
  java.runtime.version => 1.6.0_65-b14-462-11M4609
  java.vm.name => Java HotSpot(TM) 64-Bit Server VM
  java.vm.version => 20.65-b04-462
  java.vm.vendor => Apple Inc.
  java.vm.info => mixed mode
  java.awt.graphicsenv => apple.awt.CGraphicsEnvironment
  java.specification.name => Java Platform API Specification
  java.specification.version => 1.6
  sun.cpu.endian => little
  sun.desktop => null
  file.separator => /

The up-to-date check says: REMIND_LATER

Information relevant to JAVA_HOME related problems:

  JAVA_HOME is set to: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  imagej.dir => /Applications/Fiji.app

Information about the version of each plugin:

Activated update sites:
ImageJ: http://update.imagej.net/ (last check:20140911002552)
Fiji: http://fiji.sc/update/ (last check:20140905033405)
3D ImageJ Suite: http://sites.imagej.net/Tboudier/ (last check:20140604080506)
BAR: http://sites.imagej.net/Tiago/ (last check:20140822152009)
Bio-Formats: http://sites.imagej.net/Bio-Formats/ (last check:20140911032642)
MOSAIC ToolSuite: http://mosaic.mpi-cbg.de/Downloads/update/Fiji/MosaicToolsuite/ (last check:20140801113045)
My Site: http://sites.imagej.net/Miura/ (last check:20140718160940)

Files not up-to-date:
  13a1ff78 (MODIFIED) 20140811141911 Contents/Info.plist
  88cd0f15 (LOCAL_ONLY) 20140204193446 luts/Random.lut
  d2991f70 (LOCAL_ONLY) 20140214181144 plugins/3Dtrack_viewer-1.0.0.jar
  a86ed007 (LOCAL_ONLY) 20070412112742 plugins/Convex_Hull_Plus.class
  7ddd8ad9 (LOCAL_ONLY) 20121002124559 plugins/Difference_Tracker_v0.1.jar
  c80a1691 (LOCAL_ONLY) 20140401164935 plugins/Dot_Detect3D-2.0.0.jar
  14c5d84e (LOCAL_ONLY) 20140409120244 plugins/Dot_Linker-1.0.0.jar
  1ada7f41 (LOCAL_ONLY) 20121124173030 plugins/Drop_Script-1.0.0.jar
  f3daa1ce (LOCAL_ONLY) 20130607161238 plugins/Foci3D_tracker.jar-1.0.0.jar
  46413fe4 (LOCAL_ONLY) 20140205191425 plugins/GLCM2_-1.0.0.jar
  31931ef0 (LOCAL_ONLY) 20130903102924 plugins/JFilament.jar
  03fd8a19 (LOCAL_ONLY) 20140414173812 plugins/JRI.jar
  4c53d0c4 (LOCAL_ONLY) 20140414173812 plugins/JRIEngine.jar
  2b6107a0 (MODIFIED) 20140911154422 plugins/JRuby_Interpreter-2.0.0-SNAPSHOT.jar
  097c846c (LOCAL_ONLY) 20140407154646 plugins/Microscope_Communicator-1.1.2.jar
  f9527db1 (LOCAL_ONLY) 20131104190234 plugins/MultiStackRegistration_-1.46.0.jar
  093afa1c (LOCAL_ONLY) 20131028155040 plugins/PTA_-1.0.0.jar
  512e30a7 (LOCAL_ONLY) 20131108124104 plugins/ParticleTracker_Mod-1.0.0.jar
  626fd575 (LOCAL_ONLY) 20130910105341 plugins/REngine.jar
  7c21e07f (LOCAL_ONLY) 20140121193735 plugins/Radial_Profile-2.0.0.jar
  6e8e45ea (LOCAL_ONLY) 20130910105346 plugins/RserveEngine.jar
  088c1815 (LOCAL_ONLY) 20130912142810 plugins/Running_ZProjector.class
  adc3b936 (LOCAL_ONLY) 20121114104504 plugins/Scala_Interpreter-1.0.1.jar
  5dd799b2 (LOCAL_ONLY) 20131003193447 plugins/Scripts/EMBL/Open_Plugins_Folder.py
  d290c110 (LOCAL_ONLY) 20120612191944 plugins/commons-io-2.4.jar
  5f000840 (LOCAL_ONLY) 20131127165433 plugins/embltools_-1.0.0.jar
  7d5b3965 (LOCAL_ONLY) 20120829144523 plugins/javacv.jar
  e9dab53e (LOCAL_ONLY) 20131002123556 plugins/jericho-html-3.2.jar
  e1690f66 (LOCAL_ONLY) 20120306130454 plugins/jf_plugins.jar
  6bb55918 (LOCAL_ONLY) 20140617171105 plugins/limtools_-0.0.12.jar
  700c7d8d (LOCAL_ONLY) 20131002123556 plugins/mongo-2.10.1.jar
  512348bb (LOCAL_ONLY) 20140414173812 plugins/romanface.jar
  e52d2b9a (LOCAL_ONLY) 20121113111926 plugins/scala-compiler-2.10.0-SNAPSHOT.jar
  fcc003d7 (LOCAL_ONLY) 20121113104615 plugins/scala-library-2.10.0-SNAPSHOT.jar
  de055dbc (LOCAL_ONLY) 20121113111924 plugins/scala-reflect-2.10.0-SNAPSHOT.jar
  3b763e50 (LOCAL_ONLY) 20131002123556 plugins/swing-layout-1.0.4.jar
  00d542b0 (LOCAL_ONLY) 20140425145333 plugins/tango_.jar
  d6af8529 (LOCAL_ONLY) 20140408131017 plugins/testClass.class

@CMCI OK, that helped. It looks like this is actually a problem just with the JRuby interpreter.

If the interpreter is allowed to start up JRuby, you get these errors in both the interpreter and script editor.
If you start up the script editor and run a JRuby script first, the JRuby engine will start up clean and you can execute scripts with no problems (that I'm currently aware of).

Moving this to: fiji/JRuby_Interpreter#2