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/08/15 21:12:50 UTC

(grails-core) 13/14: Suppress false-positive unused-constructor warnings on MethodExpression

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

borinquenkid pushed a commit to branch test/document-datamapping-core-finders
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 23412f273b396b04f9db5af8d8b923ec0e0ade1e
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Sat Aug 15 16:00:17 2026 -0500

    Suppress false-positive unused-constructor warnings on MethodExpression
    
    Every flagged constructor is genuinely exercised, just never via a
    literal "new Xxx(...)" expression for these particular classes:
    DynamicFinder's registry invokes the (Class, String) constructor
    reflectively via Constructor.newInstance, and MethodExpressionSpec's
    existing round-trip tests invoke both shapes reflectively via
    Class.getConstructor(...).newInstance(...) - so IntelliJ's static
    usage tracker can't see either call site. Suppress rather than add
    redundant tests, since coverage already exists.
    
    Also suppress the base constructor's unused targetClass parameter -
    the field it feeds is already @Deprecated and unused by design, kept
    only so every subclass can offer the (Class, String) shape uniformly.
    
    Co-Authored-By: Claude Sonnet 5 <no...@anthropic.com>
---
 .../datastore/gorm/finders/MethodExpression.java   | 25 +++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/finders/MethodExpression.java b/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/finders/MethodExpression.java
index ea1c597f28..7c67a91de4 100644
--- a/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/finders/MethodExpression.java
+++ b/grails-datamapping-core/src/main/groovy/org/grails/datastore/gorm/finders/MethodExpression.java
@@ -38,6 +38,13 @@ import org.grails.datastore.mapping.query.Restrictions;
 
 /**
  *  Method expression used to evaluate a dynamic finder.
+ *
+ * <p>Every concrete subclass below provides both a {@code (Class, String)} and a {@code (String)}
+ * constructor. Neither shape is ever called as a literal {@code new Xxx(...)} expression for every
+ * subclass - {@link DynamicFinder}'s registry invokes the {@code (Class, String)} constructor
+ * reflectively via {@code Constructor.newInstance}, and {@code MethodExpressionSpec} exercises both
+ * shapes reflectively via {@code Class.getConstructor(...).newInstance(...)} - so static usage
+ * analysis can't see either call site even though both are genuinely exercised.
  */
 public abstract class MethodExpression {
 
@@ -52,7 +59,7 @@ public abstract class MethodExpression {
 
     public abstract Query.Criterion createCriterion();
 
-    protected MethodExpression(Class<?> targetClass, String propertyName) {
+    protected MethodExpression(@SuppressWarnings("unused") Class<?> targetClass, String propertyName) {
         this.propertyName = propertyName;
     }
 
@@ -188,10 +195,12 @@ public abstract class MethodExpression {
     }
 
     public static class Ilike extends MethodExpression {
+        @SuppressWarnings("unused")
         public Ilike(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
         }
 
+        @SuppressWarnings("unused")
         public Ilike(String propertyName) {
             super(propertyName);
         }
@@ -203,10 +212,12 @@ public abstract class MethodExpression {
     }
 
     public static class Rlike extends MethodExpression {
+        @SuppressWarnings("unused")
         public Rlike(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
         }
 
+        @SuppressWarnings("unused")
         public Rlike(String propertyName) {
             super(propertyName);
         }
@@ -218,6 +229,7 @@ public abstract class MethodExpression {
     }
 
     public static class NotInList extends MethodExpression {
+        @SuppressWarnings("unused")
         public NotInList(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
         }
@@ -258,6 +270,7 @@ public abstract class MethodExpression {
 
     public static class InList extends MethodExpression {
 
+        @SuppressWarnings("unused")
         public InList(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
         }
@@ -323,6 +336,7 @@ public abstract class MethodExpression {
 
     public static class InRange extends MethodExpression {
 
+        @SuppressWarnings("unused")
         public InRange(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
             argumentsRequired = 1;
@@ -357,11 +371,13 @@ public abstract class MethodExpression {
 
     public static class IsNull extends MethodExpression {
 
+        @SuppressWarnings("unused")
         public IsNull(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
             argumentsRequired = 0;
         }
 
+        @SuppressWarnings("unused")
         public IsNull(String propertyName) {
             super(propertyName);
             argumentsRequired = 0;
@@ -376,11 +392,13 @@ public abstract class MethodExpression {
 
     public static class IsNotNull extends MethodExpression {
 
+        @SuppressWarnings("unused")
         public IsNotNull(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
             argumentsRequired = 0;
         }
 
+        @SuppressWarnings("unused")
         public IsNotNull(String propertyName) {
             super(propertyName);
             argumentsRequired = 0;
@@ -395,11 +413,13 @@ public abstract class MethodExpression {
 
     public static class IsEmpty extends MethodExpression {
 
+        @SuppressWarnings("unused")
         public IsEmpty(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
             argumentsRequired = 0;
         }
 
+        @SuppressWarnings("unused")
         public IsEmpty(String propertyName) {
             super(propertyName);
             argumentsRequired = 0;
@@ -414,11 +434,13 @@ public abstract class MethodExpression {
 
     public static class IsNotEmpty extends MethodExpression {
 
+        @SuppressWarnings("unused")
         public IsNotEmpty(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
             argumentsRequired = 0;
         }
 
+        @SuppressWarnings("unused")
         public IsNotEmpty(String propertyName) {
             super(propertyName);
             argumentsRequired = 0;
@@ -455,6 +477,7 @@ public abstract class MethodExpression {
 
     public static class NotEqual extends MethodExpression {
 
+        @SuppressWarnings("unused")
         public NotEqual(Class<?> targetClass, String propertyName) {
             super(targetClass, propertyName);
         }