You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/06/04 05:25:33 UTC

(grails-core) 11/16: refactor(gorm): resolve static analysis warnings in GormEnhancer

This is an automated email from the ASF dual-hosted git repository.

borinquenkid pushed a commit to branch 8.0.x-hibernate7.gorm-registry-refactor
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit ab74454a5385d4468e13a9bf75ed15b8e7be8937
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Wed Jun 3 22:17:30 2026 -0500

    refactor(gorm): resolve static analysis warnings in GormEnhancer
---
 .../org/grails/datastore/gorm/GormEnhancer.groovy  | 48 ++++++++++++++--------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy b/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy
index 72a629698b..8c424190f9 100644
--- a/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy
+++ b/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/GormEnhancer.groovy
@@ -40,20 +40,22 @@ import org.grails.datastore.mapping.reflect.MetaClassUtils
  * @author Graeme Rocher
  */
 @CompileStatic
+@SuppressWarnings(['unused', 'GroovyUnusedDeclaration', 'GroovyAssignabilityCheck', 'MethodMayBeStatic', 'AccessToStaticFieldLockedOnInstance'])
 class GormEnhancer implements Closeable {
 
     private static final Logger log = LoggerFactory.getLogger(GormEnhancer)
     private static final GormEnhancerRegistry STATE_REGISTRY = GormEnhancerRegistry.getInstance()
 
-    private final GormRegistry registry
-    private final List<String> connectionSourceNames
-    final Datastore datastore
+    private GormRegistry registry
+    private List<String> connectionSourceNames
+    Datastore datastore
     boolean failOnError = false
     boolean markDirty = true
 
     /**
      * Whether to include external entities
      */
+    @SuppressWarnings(['unused', 'GrUnusedDeclaration'])
     boolean includeExternal = true
 
     /**
@@ -69,12 +71,25 @@ class GormEnhancer implements Closeable {
      * @param datastore The datastore (required)
      * @param transactionManager Retained for constructor compatibility
      * @param settings The connection source settings (required)
-     * @param registry The GORM registry (optional, defaults to singleton instance)
      */
     GormEnhancer(Datastore datastore,
-                 PlatformTransactionManager ignoredTransactionManager,
+                 @SuppressWarnings('unused') PlatformTransactionManager ignoredTransactionManager,
+                 ConnectionSourceSettings settings) {
+        this(datastore, ignoredTransactionManager, settings, GormRegistry.getInstance())
+    }
+
+    /**
+     * Construct a new GormEnhancer for the given arguments.
+     *
+     * @param datastore The datastore (required)
+     * @param transactionManager Retained for constructor compatibility
+     * @param settings The connection source settings (required)
+     * @param registry The GORM registry (required)
+     */
+    GormEnhancer(Datastore datastore,
+                 @SuppressWarnings('unused') PlatformTransactionManager ignoredTransactionManager,
                  ConnectionSourceSettings settings,
-                 GormRegistry registry = GormRegistry.getInstance()) {
+                 GormRegistry registry) {
         assert datastore != null, 'Datastore is required'
         assert settings != null, 'ConnectionSourceSettings is required'
         
@@ -158,6 +173,7 @@ class GormEnhancer implements Closeable {
         return qualifiers.unique()
     }
 
+    @SuppressWarnings(['unused', 'GrUnusedDeclaration'])
     List<String> getConnectionSourceNames() {
         return connectionSourceNames
     }
@@ -224,7 +240,7 @@ class GormEnhancer implements Closeable {
         def cls = e.javaClass
         ExpandoMetaClass mc = MetaClassUtils.getExpandoMetaClass(cls)
         
-        mc.static.methodMissing = { String name, args ->
+        mc.static.setProperty('methodMissing', { String name, args ->
             def api = registry.resolveStaticApi(cls)
             try {
                 return api.invokeMethod(name, args)
@@ -234,8 +250,8 @@ class GormEnhancer implements Closeable {
                 }
                 throw mme
             }
-        }
-        mc.static.propertyMissing = { String name ->
+        })
+        mc.static.setProperty('propertyMissing', { String name ->
             def api = registry.resolveStaticApi(cls)
             try {
                 return api.getProperty(name)
@@ -245,7 +261,7 @@ class GormEnhancer implements Closeable {
                 }
                 throw mpe
             }
-        }
+        })
     }
 
     @CompileDynamic
@@ -253,7 +269,7 @@ class GormEnhancer implements Closeable {
         Class cls = e.javaClass
         ExpandoMetaClass mc = MetaClassUtils.getExpandoMetaClass(cls)
         
-        mc.methodMissing = { String name, args ->
+        mc.setProperty('methodMissing', { String name, args ->
             def api = registry.resolveInstanceApi(cls)
             try {
                 return api.invokeMethod(name, args)
@@ -263,8 +279,8 @@ class GormEnhancer implements Closeable {
                 }
                 throw mme
             }
-        }
-        mc.propertyMissing = { String name ->
+        })
+        mc.setProperty('propertyMissing', { String name ->
             def api = registry.resolveInstanceApi(cls)
             try {
                 return api.getProperty(name)
@@ -274,10 +290,10 @@ class GormEnhancer implements Closeable {
                 }
                 throw mpe
             }
-        }
-        mc.propertyMissing = { String name, val ->
+        })
+        mc.setProperty('propertyMissing', { String name, val ->
             registry.resolveInstanceApi(cls).setProperty(name, val)
-        }
+        })
     }
 
 }