History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-1345
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Thomas E Enebo
Reporter: Daniel Einspanjer
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

Files added to a module via Kernel.autoload are not automatically loaded if the class they contain is extended

Created: 13/Sep/07 01:24 PM   Updated: 17/Jul/08 06:58 PM
Component/s: Core Classes/Modules
Affects Version/s: JRuby 1.1.1
Fix Version/s: JRuby 1.1+

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive overriding_plugins.zip (2 kb)


Testcase included: yes


 Description  « Hide
Discovered while trying to run a Rails project under JRuby. The project makes use of ActiveScaffold and a second plugin that extends ActiveScaffold.
AS uses autoload for all the files in its library.
The second plugin extends one of the classes in AS in the following way:

module Foo::Bar
class Baz
def a_method_new
end
alias_method_chain :a_method, :new
end
end

This works in MRI but in JRuby, the Foo::Bar::Baz class is not autoloaded and the alias causes the application to crash with an "undefined method" NameError

Attached is a test case that demonstrates the problem. Expand the zip into the vendor/plugins directory of a new rails project and attempt to start the project via jruby script/server



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Charles Oliver Nutter - 19/Oct/07 09:32 PM
Can you try this out again on trunk and 1.0 branch and see if it's still a problem? There have been a few autoload-related fixes since you reported this.

Charles Oliver Nutter - 12/May/08 03:33 PM
This does appear to still be failing in JRuby 1.1.1. Assigning to Tom to take a look before 1.1.2, since it might be easy (what with him being the autoload king and all).

Charles Oliver Nutter - 27/May/08 12:03 PM
I think we're going to need to punt this and do some homework (and hopefully get help). My naive attempt to reproduce the problem seems to work ok, so there's something more going on here.

a.rb

module Foo
  module Bar
    autoload :Baz, "b.rb"

    class Baz
      def y
        'wah'
      end
    end
  end
end

a = Foo::Bar::Baz.new
a.x
a.y

b.rb

module Foo
  module Bar
    class Baz
      def x
        'yay'
      end
    end
  end
end

Charles Oliver Nutter - 14/Jul/08 11:28 PM
Without a better test case or followup from the reporter, this is in danger of getting closed as "incomplete". Please provide a test case for the issue or help us diagnose it further please

Daniel Einspanjer - 15/Jul/08 05:41 AM
If the test case I posted no longer reproduces the issue then I'd say it would be fine to close the issue as works for me or something.
Unfortunately, I'm not currently doing any Ruby development so I don't have a sandbox handy to try to reproduce it again.

Charles Oliver Nutter - 16/Jul/08 12:43 AM
Sorry about that, I was able to reproduce it following your original instructions. I'm not going to be able to look at this, but maybe Tom will...

Thomas E Enebo - 17/Jul/08 02:44 AM
I tried this and I do not think I have did enough to reproduce this....

I installed Rails 2.0.2 (Rails 2.1 does not seem compatible with AS).

I then installed AS: ./script/plugin install http://activescaffold.googlecode.com/svn/tags/active_scaffold

I unzipped into vendor/plugins the zip provided..I get the following error in both MRI and JRuby trunk (and it appears that autoload seems to be finding plugin1):

enebo:01:27 ~/workspace/jruby_trunk/hoh 953% /usr/bin/ruby script/server 
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
FirstPlugin module loaded
Exiting
/Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/rails/plugin.rb:77:in `evaluate_init_rb': undefined method `configuration' for "second.rb":String (NoMethodError)
	from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
	from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/rails/plugin.rb:75:in `evaluate_init_rb'
	from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/rails/plugin.rb:39:in `load'
	from /Users/enebo/workspace/jruby_trunk/hoh/vendor/plugins/second_plugin/init.rb:1:in `evaluate_init_rb'
	from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/rails/plugin.rb:79:in `evaluate_init_rb'
	from /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
	from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/rails/plugin.rb:75:in `evaluate_init_rb'
	from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/rails/plugin.rb:39:in `load'
	 ... 34 levels...
	from /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
	from script/server:3

Thomas E Enebo - 17/Jul/08 06:58 PM
Bumping...not getting done today