Repository navigation
Description
Summary
A Grails 7 plugin that ships a generic trait containing fields cannot be used by a Grails 8 application. The Groovy 4 compiler emitted a non-generic <Trait>$Trait$FieldHelper interface for such traits, while the Groovy 5 compiler used by Grails 8 emits a generic one and, when compiling an implementing class, writes a parameterized reference to it.
The result is a class whose Signature attribute references FieldHelper<T> while the actual interface on the classpath declares zero type parameters. The class loads, but any call to Class.getGenericInterfaces() throws:
java.lang.reflect.MalformedParameterizedTypeException: Mismatch of count of formal and actual type arguments in constructor of <Trait>$Trait$FieldHelper: 0 formal argument(s) 1 actual argument(s)
java.beans.Introspector, Spring, and Jackson all call getGenericInterfaces(), so this fires on ordinary application paths.
Discovered while testing released Grails 7 plugins against 8.0.0-M5.
Grails Version
8.0.0-M5
Java / Groovy Version
Java 21.0.11 (Corretto), Groovy 5.0.8, Spring Boot 4.1.0, Spring Framework 7.0.8
Real plugin affected
org.grails.plugins:grails-logical-delete:3.0.0 - the Grails 7 release announced in #15044. Its public API is the generic trait grails.logical.delete.LogicalDelete<D>, which has fields.
Steps to Reproduce
- Generate a stock web app with the published 8.0.0-M5 distribution.
- Add
implementation "org.grails.plugins:grails-logical-delete:3.0.0". - Add a domain class implementing the plugin trait:
package logical.delete
import grails.logical.delete.LogicalDelete
class LogicalDeletedRecord implements LogicalDelete<LogicalDeletedRecord> {
String name
static constraints = { name nullable: false }
}- Exercise it through the ordinary public GORM API:
@Integration
@Rollback
class LogicalDeleteCompatibilitySpec extends Specification {
void 'delete hides a logical-delete domain instance from public GORM lookups'() {
given:
LogicalDeletedRecord record = new LogicalDeletedRecord(name: 'release-3.0.0').save(failOnError: true, flush: true)
...
}
}Actual Behaviour
The plugin resolves and loads - logicalDelete (3.0.0) appears in the plugin list - and the context starts. The test fails on the very first line, the map constructor:
java.lang.reflect.MalformedParameterizedTypeException: Mismatch of count of formal and actual type arguments in constructor of grails.logical.delete.LogicalDelete$Trait$FieldHelper: 0 formal argument(s) 1 actual argument(s)
at java.base/java.lang.Class.getGenericInterfaces(Class.java:1298)
at java.desktop/com.sun.beans.TypeResolver.prepare(TypeResolver.java:312)
at java.desktop/java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:391)
at java.desktop/java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:118)
at java.desktop/java.beans.Introspector.getTargetMethodInfo(Introspector.java:1030)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:446)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:195)
at logical.delete.LogicalDeleteCompatibilitySpec.$tt__$spock_feature_0_0(LogicalDeleteCompatibilitySpec.groovy:28)
Root cause evidence
javap on the plugin jar (compiled by Groovy 4 for Grails 7) - the trait is generic but its FieldHelper is not:
public interface grails.logical.delete.LogicalDelete<D extends java.lang.Object> extends org.grails.datastore.gorm.GormEntity<D>
Signature: <D:Ljava/lang/Object;>Ljava/lang/Object;Lorg/grails/datastore/gorm/GormEntity<TD;>;
public interface grails.logical.delete.LogicalDelete$Trait$FieldHelper
javap on the domain class compiled by Grails 8 - it references that non-generic interface with a type argument:
public class logical.delete.LogicalDeletedRecord extends java.lang.Object
implements grails.logical.delete.LogicalDelete<logical.delete.LogicalDeletedRecord>,
grails.logical.delete.LogicalDelete$Trait$FieldHelper<logical.delete.LogicalDeletedRecord>,
org.grails.datastore.mapping.dirty.checking.DirtyCheckable$Trait$FieldHelper,
org.grails.datastore.gorm.GormValidateable$Trait$FieldHelper,
groovy.lang.GroovyObject
Note the contrast in the same signature: the Grails 8 (Groovy 5 compiled) DirtyCheckable$Trait$FieldHelper and GormValidateable$Trait$FieldHelper are non-generic traits and are referenced without type arguments, so they are fine.
Confirming that Groovy 5 is self-consistent, this probe compiled inside the same 8.0.0-M5 app produces a generic FieldHelper:
trait GenericFieldTrait<D> {
String probeField
D probeValue
}
class ProbeUser implements GenericFieldTrait<ProbeUser> {}public interface probe.GenericFieldTrait$Trait$FieldHelper<D extends java.lang.Object>
Signature: <D:Ljava/lang/Object;>Ljava/lang/Object;
public class probe.ProbeUser ... implements probe.GenericFieldTrait<probe.ProbeUser>, probe.GenericFieldTrait$Trait$FieldHelper<probe.ProbeUser>, groovy.lang.GroovyObject
So Groovy 5 consistently emits FieldHelper<D> and references it as FieldHelper<T>. Against a Groovy 4-compiled plugin whose FieldHelper has no type parameters, the emitted signature is invalid.
Expected Behaviour
Either a Grails 7 plugin exposing a generic trait with fields remains usable on Grails 8, or the incompatibility is detected and reported clearly (and documented), rather than surfacing as a MalformedParameterizedTypeException from JavaBeans introspection.
Impact
This affects any Grails 7 plugin whose public extension point is a generic trait carrying fields, which is a common plugin pattern for GORM-facing traits. The failure mode is poor: resolution, plugin discovery, and startup all succeed, and the error appears later from an unrelated-looking JDK introspection frame.
Plugins whose traits are non-generic are unaffected - verified in the same sweep with grails-shiro:6.0.0, whose GrailsShiroRealm$Trait$FieldHelper and TypedNamedArgs$Trait$FieldHelper are non-generic and which loads and wires correctly on 8.0.0-M5.
Suggested resolution
Options for discussion:
- Detect the mismatch when Grails compiles a class against a trait whose
FieldHelperarity does not match, and emit a clear compile-time error naming the plugin and trait instead of producing an invalid signature. - Raise upstream with Groovy if the Groovy 4 to Groovy 5
FieldHelpergenerics change is considered a trait ABI break that should be tolerated when compiling against older trait bytecode. - At minimum, document this in the Grails 8 upgrade guide's plugin-compatibility section: a Grails 7 plugin exposing a generic trait with fields must be recompiled with Groovy 5 and re-released for Grails 8.
Notes
Found in a broader sweep of released Grails 7 plugins against 8.0.0-M5. Related compatibility-shim precedents: #16011 (legacy command plugins) and #16101 (legacy Holders access during doWithSpring).
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
jamesfredley commentedon Aug 10, 2026
Ecosystem impact scan
To size how many published plugins are affected, I scanned the released jars of 17 Grails plugins for the mismatch described above: a generic trait whose Groovy 4 compiled
$Trait$FieldHelperis non-generic. Any class compiled by Grails 8 (Groovy 5) against such a trait gets an invalidSignatureattribute and throwsMalformedParameterizedTypeExceptiononClass.getGenericInterfaces().Detection method per jar: locate every
*$Trait$FieldHelper.class,javapboth it and its owning trait, and flag the casetraitGeneric=true+helperGeneric=false.The scan reproduces both of the empirical results I already had, which validates it:
grails-logical-delete:3.0.0is flagged, and it is the plugin that actually failed at runtime in the report above.grails-shiro:6.0.0andgrails-quartz:4.0.1are not flagged, and both loaded and worked correctly on 8.0.0-M5 in the same sweep.Results
org.grails.plugins:grails-logical-delete:3.0.0grails.logical.delete.LogicalDeletetraitGeneric=true,helperGeneric=false)org.grails.plugins:audit-logging:6.0.0grails.plugins.orm.auditable.StampabletraitGeneric=true,helperGeneric=false)org.grails.plugins:audit-logging:6.0.0grails.plugins.orm.auditable.Auditableorg.grails.plugins:grails-shiro:6.0.0GrailsShiroRealm,TypedNamedArgsorg.apache.grails:grails-quartz:4.0.1grails.plugins.quartz.QuartzJoborg.grails.plugins:spring-security-core:7.0.0-M3CommandLineHelper,SkipBootstraporg.grails.plugins:database-migration:9.0.0-M3spring-security-rest,spring-security-acl,spring-security-ui,grails-web-console:7.1.0,grails-redis:5.0.1,grails-elasticsearch:5.1.0,mongodb:9.0.0-M3,grails-cache-redis:6.0.0-RC1,cache-ehcache:5.0.0-RC1,grails-export:7.1.0,asynchronous-mail:3.1.2Why this matters beyond logical-delete
grails.plugins.orm.auditable.Stampablefromaudit-loggingis the more significant hit. It is a widely used trait that applications apply directly to their own domain classes, so every such domain class compiled under Grails 8 would carry the invalid signature.That failure is currently masked:
audit-logging:6.0.0already fails earlier duringdoWithSpringfor an unrelated reason (theHolders.grailsApplicationtiming issue addressed by #16101). Once that is resolved, this trait problem becomes the next blocker for the same plugin.Takeaway
The condition is narrow but not rare: it needs a trait that is both generic and carries fields. Most plugin traits are one or the other, which is why the majority of the sample is unaffected. But when it does apply, the plugin is unusable and the error points at JDK introspection rather than at the plugin, so it is very hard to diagnose from the stack trace alone.
jamesfredley commentedon Aug 10, 2026
Runtime confirmation for
StampableThe
Stampableentry in my scan above was static analysis, so I verified it empirically. It reproduces, and it does so without any Spring context - plain compilation plus reflection is enough.Setup: stock
grails create-app --profile=webon the published 8.0.0-M5 distribution, with onlyimplementation "org.grails.plugins:audit-logging:6.0.0"and a single class applying the plugin's public trait exactly as the plugin documents:
A plain unit test (
src/test, no@Integration, no application context):Both fail:
with the same message shape as
LogicalDelete:And
javapon the Grails 8 compiled class shows the invalid signature being emitted, the type argument on aFieldHelperthat has none:Again note the contrast within one signature: the Grails 8 compiled
DirtyCheckable$Trait$FieldHelperandGormValidateable$Trait$FieldHelperappear correctly without type arguments.Why this raises the severity
Stampableis applied by application authors to their own domain classes, so the blast radius is the user's code rather than a single plugin internal.audit-logging:6.0.0fails earlier duringdoWithSpringfor the unrelatedHolderstiming reason in Add opt-in legacy Holder shim for early plugin registration #16101. Fixing Add opt-in legacy Holder shim for early plugin registration #16101 alone will not make the plugin usable - this surfaces immediately afterwards.jamesfredley commentedon Oct 2, 2026
A Grails 7 plugin that exposes a generic trait with fields still fails on Grails 8 with
MalformedParameterizedTypeExceptionmentioning$Trait$FieldHelper. There is no compile-time check that names the plugin and trait, and Groovy was not changed to accept the olderFieldHelperbytecode. Non-generic traits are not part of this failure.The minimum requested here is now in the Grails 8 upgrade guide, section 23.2, "Groovy 4 trait and AST-transform bytecode":
https://grails.apache.org/docs/8.0.x/guide/upgrading.html#_23_2_groovy_4_trait_and_ast_transform_bytecode
The plugin's trait has to be recompiled with Groovy 5 and released for Grails 8. Application code cannot repair the published jar. That section landed in #16141 (
2c8b338f1ce, 2026-08-12) and is inv8.0.0-M6,v8.0.0-RC1, andv8.0.0-RC2.