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

Randomly changed hash key in overriden []= method in Hash inherited class

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.2, JRuby 1.6.4
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: Core Classes/Modules
    • Labels:
      None
    • Environment:
      Ubuntu 10.04 (2.6.32-33)
      java 1.6.0_26-b03
    • Number of attachments :
      0

      Description

      Found this problem trying to run Machinist v2.0.0beta2 but it happens in irb as well.
      Here is a snippet I ran in a console. In my environment it randomly fails on 48th-49th iteration. After self[*keys] = [] empty array get added to keys and having the key is changed super(key) returns nil.

      class AA < Hash
        def []=(*keys)
          value = keys.pop
          super(keys, value)
        end
      
        def [](*keys)
          if !has_key?(keys)
            p keys
            self[*keys] = []
            p keys
          end
          super(keys)
        end
      end
      
      def go(h,count)
        count.times do |i|
          key=[i,i]
          h[key]<<i
        end
      end
      
      go(AA.new, 100)
      

        Activity

        Hide
        Hiro Asari added a comment -

        Can you check this with the master? You can grab a snapshot from http://ci.jruby.org/snapshots/ It appears to be fixed there.

        Show
        Hiro Asari added a comment - Can you check this with the master? You can grab a snapshot from http://ci.jruby.org/snapshots/ It appears to be fixed there.
        Hide
        Ivan Vystoskiy added a comment -

        Yes, I can confirm that it is fixed in jruby-1.7.0.dev
        Thanks!

        Show
        Ivan Vystoskiy added a comment - Yes, I can confirm that it is fixed in jruby-1.7.0.dev Thanks!

          People

          • Assignee:
            Unassigned
            Reporter:
            Ivan Vystoskiy
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: