Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6067

MetaClassImpl triggers new entries for maps with default

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.9, 2.1.2
    • 2.4.6
    • groovy-jdk
    • None

    Description

      The following code:

      def map = [:].withDefault { 'foo' }
      Map.metaClass.bar = { -> 'ok' }
      assert map.bar() == 'ok'
      assert !map.containsKey('bar')
      
      println map.keySet()
      

      Fails at the second assertion, because MetaClassImpl triggers an unexpected get() into the map.

      Note that the behaviour is not the same if you use a per instance MC, which probably means inconsistencies...

      Attachments

        Activity

          People

            pascalschumacher Pascal Schumacher
            melix Cédric Champeau
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: