groovy
  1. groovy
  2. GROOVY-4094

failures when resolving collection properties with the IBM jdk

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Linux, Groovy 1.6.5 1.6.8 1.7.1
    • Number of attachments :
      0

      Description

      There are some inconstancies in how Groovy works on the Sun and IBM jdk in regards to accessing properties on the collection object versus the properties of the contents of a collection.

      Consider the following groovy script

      List<String> list = new ArrayList<String>();
      list.add("hello");
      list.add("world");
      print list.size

      On the Sun jdk this will output '2' as the result for list.size, on the IBM jdk it will fail with the following error

      groovy.lang.MissingPropertyException: Exception evaluating property 'size' for java.util.ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: size for class: java.lang.String
      at ConsoleScript8.run(ConsoleScript8:4)

      Changing the value to list.size() does make it work on both JDKs

        Activity

        Hide
        Roshan Dawrani added a comment -

        This is no groovy issue. It is due to difference in implementation of ArrayList on Sun/IBM JVM. (and due to the fact that groovy allows access to private members, but that's a known issue)

        On Sun JVM, the ArrayList class has a private property called size, that's why list.size returns you the value of that property.

        On IBM JVM, the ArrayList class does not have any property called size, in that case groovy behavior is to apply the property on each member of the collection and collect values of all member.property in a collection and return. So, it now expects "size" property on each collection member, but that also fails because String class also does not have any size property.

        If you are interested in getting the size of the list then list.size is not the groovy-way to get it anyway - it is list.size().

        Show
        Roshan Dawrani added a comment - This is no groovy issue. It is due to difference in implementation of ArrayList on Sun/IBM JVM. (and due to the fact that groovy allows access to private members, but that's a known issue) On Sun JVM, the ArrayList class has a private property called size, that's why list.size returns you the value of that property. On IBM JVM, the ArrayList class does not have any property called size, in that case groovy behavior is to apply the property on each member of the collection and collect values of all member.property in a collection and return. So, it now expects "size" property on each collection member, but that also fails because String class also does not have any size property. If you are interested in getting the size of the list then list.size is not the groovy-way to get it anyway - it is list.size().

          People

          • Assignee:
            Unassigned
            Reporter:
            Matt Wringe
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: