borinquenkid commented on PR #16034:
URL: https://github.com/apache/grails-core/pull/16034#issuecomment-5040627525
Thanks for the review! The scenario you're describing — two distinct
`ClassNode` instances sharing the exact same fully-qualified name — is already
covered by the test right below this one:
```groovy
void "property lookups for two distinct ClassNode instances with the exact
same unqualified name do not corrupt each other"() {
given: 'two distinct ClassNode instances - as produced by two separate
compilations - sharing an identical unqualified name'
ClassNode first = new ClassNode('Widget', Modifier.PUBLIC,
ClassHelper.OBJECT_TYPE)
first.addProperty('color', Modifier.PUBLIC, ClassHelper.STRING_TYPE,
null, null, null)
ClassNode second = new ClassNode('Widget', Modifier.PUBLIC,
ClassHelper.OBJECT_TYPE)
second.addProperty('weight', Modifier.PUBLIC, ClassHelper.Integer_TYPE,
null, null, null)
expect: 'the two ClassNode instances compare equal by name - the exact
condition that would collide in a name-keyed or equals()-keyed cache'
first == second
first.hashCode() == second.hashCode()
!first.is(second)
...
```
It goes a step further than the suggested edit by asserting `first ==
second` and matching `hashCode()`, which explicitly proves the collision
condition a name-/equals()-keyed cache would hit — exactly the regression this
fix guards against.
The test this comment is attached to intentionally covers a different case:
two `ClassNode`s that share a simple name but differ by package (so they're
*not* equal), which is a distinct scenario worth keeping separate. Given the
exact-FQN-collision case is already exercised, I'll leave both tests as-is
rather than introduce a near-duplicate.
--
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]