[ 
https://issues.apache.org/jira/browse/GROOVY-9919?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King closed GROOVY-9919.
-----------------------------

> getProperty('Foo') fails, when a function setFoo(foo [, ....]) exists (Foo 
> starting with uppercase letter)
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9919
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9919
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 3.0.5
>         Environment: Groovy  >=  3..0.5
> Java JDK jdk1.8.0_141
> Windows 7 Prof 64 bit
>            Reporter: Stefan Großkreutz
>            Priority: Major
>
> 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.
> {code:java}
> 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'
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to