This is an automated email from the ASF dual-hosted git repository. borinquenkid pushed a commit to branch test/document-datamapping-core-transformers in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 53e176748ff0644be723c5bcf7619e28a2cf90dc Author: Walter Duque de Estrada <[email protected]> AuthorDate: Thu Aug 13 14:55:03 2026 -0500 Remove the structurally-unreachable malformed-astNodes guard from LocalTransformationSupport The guard cast both array slots to their expected type before checking whether they actually were that type, so any input that would fail the check threw a plain ClassCastException from the cast itself first - the intended RuntimeException could never actually be constructed. Removed the dead branch and left a comment explaining why the two casts are trusted rather than defensively checked. Co-Authored-By: Claude Sonnet 5 <[email protected]> --- .../org/grails/compiler/gorm/LocalTransformationSupport.groovy | 9 ++++----- .../grails/compiler/gorm/LocalTransformationSupportSpec.groovy | 10 ---------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/grails-datamapping-core/src/main/groovy/org/grails/compiler/gorm/LocalTransformationSupport.groovy b/grails-datamapping-core/src/main/groovy/org/grails/compiler/gorm/LocalTransformationSupport.groovy index 588682829c..d9bd740a49 100644 --- a/grails-datamapping-core/src/main/groovy/org/grails/compiler/gorm/LocalTransformationSupport.groovy +++ b/grails-datamapping-core/src/main/groovy/org/grails/compiler/gorm/LocalTransformationSupport.groovy @@ -43,12 +43,11 @@ class LocalTransformationSupport { * (the annotation doesn't match, or the annotated node isn't a class) */ static ClassNode resolveAnnotatedClassOrNull(ASTNode[] astNodes, ClassNode expectedAnnotationType) { - AnnotatedNode parent = (AnnotatedNode) astNodes[1] + // Groovy's local-transform dispatch always supplies [AnnotationNode, AnnotatedNode] here, + // so these casts are trusted rather than defensively checked first: a shape mismatch would + // throw ClassCastException from the cast itself, before any check could run anyway. AnnotationNode node = (AnnotationNode) astNodes[0] - - if (!(astNodes[0] instanceof AnnotationNode) || !(astNodes[1] instanceof AnnotatedNode)) { - throw new RuntimeException("Internal error: wrong types: ${node.getClass()} / ${parent.getClass()}") - } + AnnotatedNode parent = (AnnotatedNode) astNodes[1] if (expectedAnnotationType != node.getClassNode() || !(parent instanceof ClassNode)) { return null diff --git a/grails-datamapping-core/src/test/groovy/org/grails/compiler/gorm/LocalTransformationSupportSpec.groovy b/grails-datamapping-core/src/test/groovy/org/grails/compiler/gorm/LocalTransformationSupportSpec.groovy index e67f295854..b2fd669813 100644 --- a/grails-datamapping-core/src/test/groovy/org/grails/compiler/gorm/LocalTransformationSupportSpec.groovy +++ b/grails-datamapping-core/src/test/groovy/org/grails/compiler/gorm/LocalTransformationSupportSpec.groovy @@ -30,16 +30,6 @@ import spock.lang.Specification * {@code LocalTransformationSupport.resolveAnnotatedClassOrNull} is the shared guard extracted * from {@link DirtyCheckTransformation} and {@link JpaGormEntityTransformation}'s * {@code visit(ASTNode[], SourceUnit)} entry points. - * <p> - * The method's malformed-{@code astNodes}-shape check is not covered here: it casts both array - * slots to {@code AnnotationNode}/{@code AnnotatedNode} before checking whether they actually are - * one, so any input that would fail the check throws a plain {@code ClassCastException} from the - * cast itself first - the intended {@code RuntimeException} with its "Internal error: wrong types" - * message can never actually be constructed, since building that message requires calling - * {@code .getClass()} on locals that only hold a non-null value once the (now un-reachable) casts - * have already succeeded. This is a pre-existing latent issue inherited unchanged from both - * original call sites, not introduced by extracting this method - it is called out here rather - * than silently left uncovered. */ class LocalTransformationSupportSpec extends Specification {
