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

getProperty('Foo') fails, when a function setFoo(foo [, ....]) exists (Foo starting with uppercase letter)

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.0.5
    • Fix Version/s: None
    • Component/s: groovy-runtime
    • Labels:
      None
    • Environment:
      Groovy >= 3..0.5
      Java JDK jdk1.8.0_141
      Windows 7 Prof 64 bit

      Description

      Hello,

      we upgrade lately from Groovy 2.4 to Groovy 3.0.4 and then to 3.0.6. From this point some of our scripts started to fail. I reduced the source to the very problem, see example below.

      Consider a class MyClass having a property Foo (mind the upper case name!).
      The class has a function setFoo( String foo, String bar = '') which acts in our case as a convenience function to set two or more other properties in the class.

      When we try to access the Property with getProperty("Foo"), we now get an Exception:

      groovy.lang.MissingPropertyException: No such property: Foo for class: MyClass
      Possible solutions: foo

      From the outside it looks as if the function creates an new lowercase property foo behind the scenes and hides or destroys the uppercase property.

      Last Groovy version where the example runs correctly ist 3.0.4, so Groovy 3.0.5 introduced the problem.

      public class MyClass {
          
          public String Foo
          public String Bar    
      
          // both these variants cause the error
          void setFoo(String foo, String bar = '' )
          // void setFoo(String foo )
          
          // these variants are working
          // void setFoo(String foo, String bar )
          // void setStateWithInfo(String foo, String bar = '' )
          {
              Foo = foo
              Bar = bar
          }     
      }
      
      MyClass myClass = new MyClass()
      myClass.Foo = '42'
      // no need to call the function actually
      // myClass.setFoo('42', 'foo info')
      assert myClass.Foo == '42'
      
      Object foo = myClass.getProperty('Foo') // <-- crashes in Groovy 3.0.5 up
      println "foo is $foo"
      assert foo == '42'
      
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              osti Stefan Gro├čkreutz
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: