[
https://issues.apache.org/jira/browse/GROOVY-3056?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149567#comment-18149567
]
ASF GitHub Bot commented on GROOVY-3056:
----------------------------------------
daniellansun opened a new pull request, #3346:
URL: https://github.com/apache/groovy/pull/3346
https://issues.apache.org/jira/browse/GROOVY-3056
ExpandoMetaClass treated a registered `get`/`set`/`is` method as a property
accessor only when the first or second character of the suffix was uppercase.
Groovy forms the accessor for a property such as `_ajax` as `get_ajax`, because
capitalizing a name that does not start with a lowercase letter leaves it
unchanged, so the closure was never installed as the property and
`getProperty("_ajax")` still returned the field.
`isPropertyName` now accepts a suffix exactly when `BeanUtils.capitalize`
leaves it unchanged. That keeps previously accepted forms (`getFoo`, `getURL`,
`getuRL`) and also recognizes `_ajax`, `$id`, and a digit-leading name.
`getfoo` / `setfoo` are still not accessors.
This is a compatible widening on the current line, not a Groovy 7-only
break. Coverage is in `Groovy3056` and the re-enabled
`RegressionTest.testGroovy3056`.
> Cannot override getter of property starting with "_" using ExpandoMetaClass
> ---------------------------------------------------------------------------
>
> Key: GROOVY-3056
> URL: https://issues.apache.org/jira/browse/GROOVY-3056
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 1.5.6
> Reporter: Peter Ledbrook
> Assignee: Daniel Sun
> Priority: Major
> Attachments: ExpandoMetaClassUnderscoreTests.groovy
>
>
> For most properties you can use code like this to override property read
> access:
> {code}
> MyClass.metaClass.getMyProp = {-> return "New value" }
> {code}
> Groovy's {{getProperty()}} method will then call the above code so objects of
> class {{MyClass}} will appear to have the new value for that property.
> However, if the property starts with an underscore, this behaviour breaks
> down:
> {code}
> MyClass.metaClass.get_ajax = {-> return "Some value" }
> {code}
> The above method will not be called if one uses {{getProperty("_ajax")}}.
> Test case attached.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)