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

ExpandoMetaClass returns expando properties twice

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.5.1
    • 1.5.2
    • groovy-jdk
    • None
    • WIndows XP SP 2

    Description

      i like to use the ExpandoMetaClass to add properties and methods during runtime.
      For testing purposes I wrote:

      class Foo{

      }
      println Foo.metaClass
      def a1 = new Foo();
      println a1.metaClass.class

      Foo.metaClass.expando = true;

      println Foo.metaClass.class
      def a2 = new Foo();
      println a2.metaClass.class

      a2.metaClass.test = "value"
      println a2.test
      println a2.metaClass.properties.name

      Unfortunately "println a2.metaClass.properties.name" returns
      ["expando", "test", "class", "expando", "metaClass", "test"]

      I think this is related to the getProperties method in ExpandoMetaClass:

      public List getProperties()

      { List propertyList = new ArrayList(); propertyList.addAll(expandoProperties.values()); propertyList.addAll(super.getProperties()); return propertyList; }

      At first it reads the properties form the local list and adds the properties for MetaClassImpl afterwards. Why are all expando properties are hold twice?

      Attachments

        Activity

          People

            graemerocher Graeme Rocher
            christoph.hartmann Christoph Hartmann
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: