Copilot commented on code in PR #16721:
URL: https://github.com/apache/grails-core/pull/16721#discussion_r4343849973
##########
grails-datastore-core/src/main/groovy/org/grails/datastore/mapping/reflect/NameUtils.java:
##########
@@ -104,9 +104,8 @@ public static String getGetterName(String propertyName,
boolean useBooleanPrefix
* @return The class name
*/
public static String getClassName(Class clazz) {
- final String sn = clazz.getSimpleName();
- if (sn.contains(DOLLAR_SEPARATOR)) {
- return clazz.getSuperclass().getName();
+ while (clazz.getSimpleName().contains(DOLLAR_SEPARATOR) &&
clazz.getSuperclass() != null) {
+ clazz = clazz.getSuperclass();
}
return clazz.getName();
Review Comment:
This method uses the raw Class type, which triggers unnecessary rawtype
warnings in Java. Since you’re already modifying this method, consider changing
the signature to use Class<?> for better type safety without affecting runtime
behavior.
##########
grails-data-hibernate7/core/src/test/groovy/org/grails/orm/hibernate/proxy/ByteBuddyGroovyProxyFactorySpec.groovy:
##########
@@ -41,6 +43,29 @@ class ByteBuddyGroovyProxyFactorySpec extends Specification {
ByteBuddyState state = new ByteBuddyState()
ByteBuddyProxyHelper helper = new ByteBuddyProxyHelper(state)
+ void "a wrapped Hibernate proxy resolves the entity name and validation
API without initialization"() {
+ given:
+ Session session = datastore.sessionFactory.openSession()
+ Class entityAlias = GroovyProxyFactoryEntity
+
+ when:
+ def proxy = session.getReference(entityAlias, 1L)
+ Class proxyClass = proxy.getClass()
+
+ then:
+ proxyClass.superclass.superclass == entityAlias
Review Comment:
This assertion depends on Hibernate/ByteBuddy’s exact generated superclass
chain depth, which is an implementation detail and may change across
versions/configurations. To reduce brittleness while still validating the
regression, prefer asserting only the observable contract: that the proxy class
is not the entity class, and that NameUtils.getClassName(proxyClass) resolves
to the entity name (optionally also assert that unwrapping works for
proxyClass.superclass if you want a minimal intermediate check).
##########
grails-data-hibernate5/core/src/test/groovy/org/grails/orm/hibernate/proxy/ByteBuddyGroovyProxyFactorySpec.groovy:
##########
@@ -39,6 +41,29 @@ class ByteBuddyGroovyProxyFactorySpec extends Specification {
ByteBuddyProxyHelper helper = new
GrailsBytecodeProvider().getByteBuddyProxyHelper()
+ void "a wrapped Hibernate proxy resolves the entity name and validation
API without initialization"() {
+ given:
+ Session session = datastore.sessionFactory.openSession()
+ Class entityAlias = GroovyProxyFactoryEntity
+
+ when:
+ def proxy = session.getReference(entityAlias, 1L)
+ Class proxyClass = proxy.getClass()
+
+ then:
+ proxyClass.superclass.superclass == entityAlias
+ NameUtils.getClassName(entityAlias) == entityAlias.name
+ NameUtils.getClassName(proxyClass.superclass) == entityAlias.name
+ NameUtils.getClassName(proxyClass) == entityAlias.name
+ GormEnhancer.findValidationApi(proxyClass) != null
+
GormEnhancer.findValidationApi(proxyClass).is(GormEnhancer.findValidationApi(entityAlias))
Review Comment:
The test calls GormEnhancer.findValidationApi(proxyClass) twice (and also
calls findValidationApi(entityAlias) inline), which can repeat
reflection/introspection work and makes failures a bit harder to read. Store
these results in local variables (e.g., proxyValidationApi/entityValidationApi)
and assert against them.
--
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]