Copilot commented on code in PR #15548:
URL: https://github.com/apache/grails-core/pull/15548#discussion_r3028874908
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler.java:
##########
@@ -58,6 +58,11 @@ public boolean isInitialized(Object o) {
return li.wasInitialized();
}
+ Boolean groovyProxyInit = GroovyProxyInterceptorLogic.isInitialized(o);
+ if (groovyProxyInit != null) {
+ return groovyProxyInit;
Review Comment:
`groovyProxyInit` is a bit ambiguous because it reads like an action rather
than a state. Consider renaming to something state-oriented like
`groovyProxyInitialized` (or `groovyProxyIsInitialized`) to make the boolean
meaning clearer at the call site.
```suggestion
Boolean groovyProxyInitialized =
GroovyProxyInterceptorLogic.isInitialized(o);
if (groovyProxyInitialized != null) {
return groovyProxyInitialized;
```
##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/HibernateProxyHandler7Spec.groovy:
##########
@@ -145,6 +145,23 @@ class HibernateProxyHandler7Spec extends
HibernateGormDatastoreSpec {
proxyHandler.isInitialized(location)
}
+ void "test isInitialized for a Groovy proxy before initialization"() {
+ given:
+ def originalFactory = manager.session.mappingContext.proxyFactory
+ manager.session.mappingContext.proxyFactory = new GroovyProxyFactory()
+ Location location = new Location(name: "Test Location").save(flush:
true)
+ manager.session.clear()
+ manager.hibernateSession.clear()
+
+ Location proxyLocation = Location.proxy(location.id)
+
+ expect:
+ !proxyHandler.isInitialized(proxyLocation)
Review Comment:
This test asserts the initialization state, but it doesn’t explicitly assert
that `proxyLocation` is actually a *Groovy* proxy (vs another proxy type or a
fully-initialized instance). To make the test robust and ensure it exercises
the new Groovy-proxy branch, add an assertion that `proxyLocation.metaClass` is
a `ProxyInstanceMetaClass` (or otherwise validate it is a Groovy proxy) before
asserting `isInitialized`.
--
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]