JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6658

Problem when setting up an autoload entry, defining a class via require, then redefining the autoload entry

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: JRuby 1.7.0.pre2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Mac OS X 10.7.3, Java 1.6.0_31 64-bit server VM, JRuby 1.6.7 and master
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      Many BioRuby test cases are failing when the whole test suite is run
      under JRuby, even though most or all individual test scripts run
      successfully. I have created a minimal test case exhibiting this
      behavior, which appears to be caused by a JRuby bug relating to
      autoloads. These tests succeed under MRI (1.9.3-p194) but fail under
      JRuby 1.6.7 and a recent build from master.

      When a module creates an autoload entry, and then a child which would
      be loaded by that entry is instead loaded by directly invoking
      require, and then the autoload entry is set up again with another call
      to the parent module's #autoload method, subsequent access to the
      child module fails with "NameError: uninitialized constant ..."

      It would appear that the direct definition of a class under a module
      does not properly remove an autoload map entry; once this state is
      reached, it is possible for Module#autoload to set up another broken
      autoload map entry.

      I have created a RubySpec test case, "Module#autoload entries should NOT raise a NameError when calling #autoload, requiring the module directly, and calling #autoload again", in a pull request (https://github.com/rubyspec/rubyspec/pull/136) submitted to RubySpec. This passes on MRI 1.8.7 and 1.9.3, but not on JRuby 1.6.7 or a recent trunk build.

      I also have a more elaborate set of scripts used to elucidate the problem, along with their output, attached.

        Activity

        Hide
        Andy Lindeman added a comment -

        I've taken a stab at this with https://github.com/jruby/jruby/pull/176

        Show
        Andy Lindeman added a comment - I've taken a stab at this with https://github.com/jruby/jruby/pull/176
        Hide
        Charles Oliver Nutter added a comment -
        commit 22cd6f9ac78cfe634b997a9f2c913b8c2ea70890
        Author: Andy Lindeman <andy@highgroove.com>
        Date:   Sun May 20 10:37:21 2012 -0500
        
            Fixes JRUBY-6658
            
            * If an autoload is defined, yet the constant is defined by other means,
              another autoload for the same constant does not reset the process.
            * Fixes https://github.com/rubyspec/rubyspec/pull/136 under JRuby
        
        :100644 100644 51d4a91... a236fac... M	src/org/jruby/RubyModule.java
        
        Show
        Charles Oliver Nutter added a comment - commit 22cd6f9ac78cfe634b997a9f2c913b8c2ea70890 Author: Andy Lindeman <andy@highgroove.com> Date: Sun May 20 10:37:21 2012 -0500 Fixes JRUBY-6658 * If an autoload is defined, yet the constant is defined by other means, another autoload for the same constant does not reset the process. * Fixes https://github.com/rubyspec/rubyspec/pull/136 under JRuby :100644 100644 51d4a91... a236fac... M src/org/jruby/RubyModule.java

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Clayton Wheeler
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: