paulk-asert commented on PR #3346:
URL: https://github.com/apache/groovy/pull/3346#issuecomment-7267635859
Thanks for this. The rule looks right to me: accepting a suffix exactly when
`BeanUtils.capitalize` leaves it unchanged matches how Groovy forms accessor
names. Over all BMP identifier characters, I found no suffix accepted by the
old rule that the new one rejects. It also brings EMC closures into line with
real and mixed-in methods, where e.g. `get_r()` is already a property. On that
basis I'd keep `$` and digit-leading names too, even though the JIRA only
mentions `_`.
My main concern is the "compatible widening … not a Groovy 7-only break"
claim. Once such an accessor is registered, there are visible changes. I ran
the same script with the current and the PR versions of `ExpandoMetaClass`:
| Scenario | Before | With this PR |
|---|---|---|
| `A.metaClass.get_secret = { -> 'S' }`, then `JsonOutput.toJson(new A())` |
`{"n":"x"}` | `{"n":"x","_secret":"S"}` (also in `.properties`) |
| `get_boom` throws, then `toJson` | works | throws |
| `new U(u.properties.findAll { it.key != 'class' })` with `get_k`
registered | works | `ReadOnlyPropertyException` |
| `set_c` only, over `private _c = 'priv'`, then `toJson` | `{}` |
`{"_c":"priv"}` |
| `get_c` over `private _c`, class reads `_c` inside a closure | field value
| `get_c()` result |
| `set_v` over `private _v`, class writes `_v` inside a closure | writes the
field | calls `set_v` |
| `propertyMissing` plus `get_x`, reading `._x` | `propertyMissing` |
`get_x()` |
I checked several of these against their `getC`/`setC` equivalents, and they
match existing behaviour for conventionally named properties, so I think the
new behaviour is right. But `_name` is a common backing-field convention, and
`COMPATIBILITY.md` lists MetaClass dispatch and serialization formats among the
behaviours whose change counts as breaking. I'd treat this as 7.0 only, with no
backport to 6.0.x.
Suggested changes:
1. **Description:** replace the "compatible widening" paragraph with the
actual impact.
2. **`COMPATIBILITY.md`:** add a Groovy 7 entry covering
`getProperties()`/JSON visibility, private backing fields accessed from
closures, and `propertyMissing`.
3. **Tests:** please pin
- the `getProperties()`/JSON result after registering e.g. `get_secret`;
- a private `_field` read and written inside a closure of its own class;
- a lowercase letter with no single-char uppercase form, e.g. `getßx`.
The `capitalize` comparison handles this correctly, whereas a later
"simplification" to `!Character.isLowerCase(..)` would break it.
4. **Javadoc:**
- `isPropertyName` gives two cases where capitalization is a no-op. The
third is a lowercase letter with no single-char uppercase form, such as `ß`.
- I'd trim the rest, as it is a lot of text for a one-line change. In
particular, I'd drop the `StringIndexOutOfBoundsException` notes on
`getPropertyForGetter`/`getPropertyForSetter`: they turn an implementation
accident into a documented contract, and the latter is public API.
5. **Nits in `Groovy3056`:**
- `import groovy.lang.ExpandoMetaClass` is redundant.
- The `getOther <<` assertion in
`wrongArityUnderscoreMethodsAreNotAccessors` isn't about arity or underscores.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]