Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.1.3, JRuby 1.1.4
-
Fix Version/s: JRuby 1.2
-
Component/s: Java Integration
-
Labels:None
-
Environment:JRuby 1.1.4 and 1.1.3 on Sun Java SE build 1.6.0_07-b06 running on Win2K w/SP4
-
Number of attachments :
Description
Attempting to import a Java class (containing either named or anonymous inner classes) from a require'd JAR causes an exception.
Replicate by running the following Ruby code after downloading the stringtemplate.jar file included in this distribution http://stringtemplate.org/download.html
jruby_st2.rb
begin raise LoadError, 'missing JRuby' unless RUBY_PLATFORM == 'java' require 'java' require 'C:/temp/stringtemplate.jar' rescue LoadError => e puts "#{e.message}; exiting..." exit -1 end def purge(e) puts e.message e.backtrace.each { |i| puts i } end begin # try to import class with no inner classes import 'org.antlr.stringtemplate.AutoIndentWriter' rescue Exception => e purge e end begin # try to import class with anonymous inner class import 'org.antlr.stringtemplate.StringTemplateGroup' rescue Exception => e purge e end begin # try to import class with 2 named static final classes import 'org.antlr.stringtemplate.StringTemplate' rescue Exception => e purge e end
Running the above file using jruby jruby_st2.rb gives the following:
Exception Summary
cannot link Java class org.antlr.stringtemplate.StringTemplateGroup (eval):1:in `binding' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:67:in `eval' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:67:in `include_class' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:38:in `each' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:38:in `include_class' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:81:in `java_import' jruby-st2.rb:44 cannot link Java class org.antlr.stringtemplate.StringTemplate (eval):1:in `binding' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:67:in `eval' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:67:in `include_class' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:38:in `each' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:38:in `include_class' E:/jruby/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:81:in `java_import' jruby-st2.rb:51
I now believe that this is not a JRuby bug as adding
require 'c:/temp/antlr-2.7.7.jar' to the first begin...end block causes the code sample to work as expected without throwing link exceptions. Code was originally ported from a working Groovy example (which didn't require the ANTLR JAR at runtime) which apparently manages run-time dependencies differently.
Sorry for the red herring...