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

Issue requiring 'yaml' on SwingWorker on jruby 9.0.0.0.rc2 #3149

Closed
blerins opened this issue Jul 17, 2015 · 11 comments
Closed

Issue requiring 'yaml' on SwingWorker on jruby 9.0.0.0.rc2 #3149

blerins opened this issue Jul 17, 2015 · 11 comments
Labels
Milestone

Comments

@blerins
Copy link

@blerins blerins commented Jul 17, 2015

Hi

I have an issue requiring some libraries inside a SwingWorker. Here is a broken example:

test.rb

class LaunchThread < javax.swing.SwingWorker
  def doInBackground
    require 'yaml'
    p 'yaml'
  end

  def done
    get
  rescue java.util.concurrent.ExecutionException => ex
    raise ex.cause
  end
end

LaunchThread.new.execute

f = javax.swing.JFrame.new('Test')
f.visible = true

Execution with JRuby 9 and JRuby 1.7:

$ jruby -v
jruby 9.0.0.0.rc2 (2.2.2) 2015-07-09 ff331eb OpenJDK 64-Bit Server VM 25.60-b22 on 1.8.0_60-internal-b22 +jit [linux-amd64]
$ jruby test.rb 
Exception in thread "AWT-EventQueue-0" org.jruby.exceptions.RaiseException: (NameError) missing class name (`org.jruby.ext.psych.PsychLibrary')
    at org.jruby.javasupport.JavaUtilities.get_proxy_or_package_under_package(org/jruby/javasupport/JavaUtilities.java:54)
    at RUBY.method_missing(uri:classloader:/jruby/java/java_package_module_template.rb:14)
    at RUBY.<top>(/home/bruno/.rbenv/versions/jruby-9.0.0.0.rc2/lib/ruby/stdlib/psych.rb:4)
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:940)
    at RUBY.(root)(/home/bruno/.rbenv/versions/jruby-9.0.0.0.rc2/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1)
    at RUBY.<top>(/home/bruno/.rbenv/versions/jruby-9.0.0.0.rc2/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54)
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:940)
    at RUBY.(root)(/home/bruno/.rbenv/versions/jruby-9.0.0.0.rc2/lib/ruby/stdlib/yaml.rb:5)
    at test.doInBackground(test.rb:3)
[...]
$ jruby -v
jruby 1.7.13 (1.9.3p392) 2014-06-24 43f133c on OpenJDK 64-Bit Server VM 1.8.0_60-internal-b22 +indy [linux-amd64]
$ jruby test.rb 
"yaml"

Thanks

@enebo enebo added this to the Invalid or Duplicate milestone Jul 17, 2015
@enebo enebo added the JRuby 9000 label Jul 17, 2015
@enebo
Copy link
Member

@enebo enebo commented Jul 17, 2015

This was fixed when we reverted our context class loader change. I can run your script with HEAD.

@enebo enebo closed this Jul 17, 2015
@mkristian mkristian reopened this Jul 17, 2015
@mkristian
Copy link
Member

@mkristian mkristian commented Jul 17, 2015

when I run the test.rb on current HEAD I see all kind of stacktrace including the reported one.

and the jar with the missing class is loaded via JRuby.runtime.jruby_class_loader not with thread-context-classloader.

I am on ubuntu 15.04 with OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu1)

@enebo
Copy link
Member

@enebo enebo commented Jul 17, 2015

This is super weird:

head ~/work/ruby jruby-ruby_2_2_2 529% jruby ../snippets/yam1.rb 
"yaml"
system ~/work/ruby jruby-ruby_2_2_2 538% jruby ../snippets/yam1.rb 
Exception in thread "AWT-EventQueue-0" org.jruby.exceptions.RaiseException: (NameError) missing class name (`org.jruby.ext.psych.PsychLibrary')
    at org.jruby.javasupport.JavaUtilities.get_proxy_or_package_under_package(org/jruby/javasupport/JavaUtilities.java:54)
    at RUBY.method_missing(uri:classloader:/jruby/java/java_package_module_template.rb:14)
    at RUBY.<top>(/Users/enebo/work/jruby/lib/ruby/stdlib/psych.rb:4)
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:940)
    at RUBY.(root)(/Users/enebo/work/jruby/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1)
    at RUBY.<top>(/Users/enebo/work/jruby/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:54)
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:940)
    at RUBY.(root)(/Users/enebo/work/jruby/lib/ruby/stdlib/yaml.rb:5)
    at $_dot_dot_.snippets.yam1.doInBackground(../snippets/yam1.rb:3)

I positively did not rebuild JRuby between the two but I cannot get this script to run past the very first time I tried :|

@mkristian
Copy link
Member

@mkristian mkristian commented Jul 17, 2015

:)

@enebo
Copy link
Member

@enebo enebo commented Jul 17, 2015

I changed from Java 1.7 to 1.8 and it worked....once.

@mkristian
Copy link
Member

@mkristian mkristian commented Jul 17, 2015

I can add to the mistery: the first two times I got:

$ bin/jruby test.rb 
Exception in thread "AWT-EventQueue-0" org.jruby.exceptions.RaiseException: (IOError) closed stream
    at org.jruby.RubyIO.gets(org/jruby/RubyIO.java:2202)
    at org.jruby.RubyIO.readline(org/jruby/RubyIO.java:2582)
    at RUBY.block in data(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/stub_specification.rb:78)
    at org.jruby.RubyIO.open(org/jruby/RubyIO.java:1126)
    at org.jruby.RubyKernel.open(org/jruby/RubyKernel.java:311)
    at RUBY.data(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/stub_specification.rb:75)
    at RUBY.valid?(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/stub_specification.rb:178)
    at RUBY.block in each_stub(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/specification.rb:731)
    at RUBY.block in each_gemspec(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/specification.rb:723)
    at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1560)
    at RUBY.block in each_gemspec(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/specification.rb:722)
    at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1560)
    at RUBY.each_gemspec(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/specification.rb:721)
    at RUBY.each_stub(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/specification.rb:729)
    at RUBY.stubs(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/specification.rb:748)
    at RUBY.matching_specs(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/dependency.rb:273)
    at RUBY.to_specs(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/dependency.rb:295)
    at RUBY.to_spec(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/dependency.rb:324)
    at RUBY.gem(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/core_ext/kernel_gem.rb:64)
    at RUBY.require(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:46)
    at RUBY.<top>(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/yaml.rb:5)
    at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:940)
    at RUBY.(root)(/home/christian/projects/active/jruby/jruby/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:1)
    at test.doInBackground(test.rb:3)

but never again

@enebo
Copy link
Member

@enebo enebo commented Jul 17, 2015

Tip of the hat to @headius. This is not technically a bug. Add a 'sleep' or 'gets' at the end of the script to prevent Main thread from trying to exit and shutdown. There may be some special swing way of preventing main thread for leaving?

@blerins
Copy link
Author

@blerins blerins commented Jul 17, 2015

Shouldn't be the open JFrame enough to keep the Main thread?

@enebo
Copy link
Member

@enebo enebo commented Jul 20, 2015

@blerins Swing does not block the main thread and the actual rendering happens in Swing thread so the script falls off the end and then script finalization happens. In the occasional cases where the script does not error invokeLater triggers and the Java thread executes Ruby code which then we 'adopt' the Java thread by virtue of it executing Ruby. If it adopts this thread in time then when we fall off the main script we still have a running Ruby thread so finalization does not start.

@blerins
Copy link
Author

@blerins blerins commented Jul 20, 2015

Hummm, so I need to wait the thread to execute before reaching the end of the script.

Something like that?:

class LaunchThread < javax.swing.SwingWorker
  def doInBackground
    require 'yaml'
    p 'yaml'
  end
end

t = LaunchThread.new
t.execute
t.get

That seem to work always.

@enebo
Copy link
Member

@enebo enebo commented Jul 20, 2015

@blerins yeah that seems reasonable to me since it guarantees that executes.

@mkristian mkristian closed this in e3f84a0 Jul 20, 2015
kares referenced this issue Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.