Skip to content

Grails 7 plugins exposing a generic trait with fields fail with MalformedParameterizedTypeException on Grails 8 #16123

Closed

Description

@jamesfredley

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

  1. Generate a stock web app with the published 8.0.0-M5 distribution.
  2. Add implementation "org.grails.plugins:grails-logical-delete:3.0.0".
  3. 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 }
}
  1. 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:

  1. Detect the mismatch when Grails compiles a class against a trait whose FieldHelper arity does not match, and emit a clear compile-time error naming the plugin and trait instead of producing an invalid signature.
  2. Raise upstream with Groovy if the Groovy 4 to Groovy 5 FieldHelper generics change is considered a trait ABI break that should be tolerated when compiling against older trait bytecode.
  3. 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).

Activity

  1. jamesfredley commented on Aug 10, 2026

    @jamesfredley
    ContributorAuthor

    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$FieldHelper is non-generic. Any class compiled by Grails 8 (Groovy 5) against such a trait gets an invalid Signature attribute and throws MalformedParameterizedTypeException on Class.getGenericInterfaces().

    Detection method per jar: locate every *$Trait$FieldHelper.class, javap both it and its owning trait, and flag the case traitGeneric=true + helperGeneric=false.

    The scan reproduces both of the empirical results I already had, which validates it:

    • grails-logical-delete:3.0.0 is flagged, and it is the plugin that actually failed at runtime in the report above.
    • grails-shiro:6.0.0 and grails-quartz:4.0.1 are not flagged, and both loaded and worked correctly on 8.0.0-M5 in the same sweep.

    Results

    Plugin Trait Status
    org.grails.plugins:grails-logical-delete:3.0.0 grails.logical.delete.LogicalDelete AT RISK (traitGeneric=true, helperGeneric=false)
    org.grails.plugins:audit-logging:6.0.0 grails.plugins.orm.auditable.Stampable AT RISK (traitGeneric=true, helperGeneric=false)
    org.grails.plugins:audit-logging:6.0.0 grails.plugins.orm.auditable.Auditable not generic, safe
    org.grails.plugins:grails-shiro:6.0.0 GrailsShiroRealm, TypedNamedArgs not generic, safe
    org.apache.grails:grails-quartz:4.0.1 grails.plugins.quartz.QuartzJob not generic, safe
    org.grails.plugins:spring-security-core:7.0.0-M3 CommandLineHelper, SkipBootstrap not generic, safe
    org.grails.plugins:database-migration:9.0.0-M3 3 command traits not generic, safe
    spring-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.2 - no trait fields at all

    Why this matters beyond logical-delete

    grails.plugins.orm.auditable.Stampable from audit-logging is 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.0 already fails earlier during doWithSpring for an unrelated reason (the Holders.grailsApplication timing 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.

  2. jamesfredley commented on Aug 10, 2026

    @jamesfredley
    ContributorAuthor

    Runtime confirmation for Stampable

    The Stampable entry 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=web on the published 8.0.0-M5 distribution, with only

    implementation "org.grails.plugins:audit-logging:6.0.0"

    and a single class applying the plugin's public trait exactly as the plugin documents:

    package stampable
    
    import grails.plugins.orm.auditable.Stampable
    
    class StampedRecord implements Stampable<StampedRecord> {
        String name
    }

    A plain unit test (src/test, no @Integration, no application context):

    class StampableTraitSpec extends Specification {
    
        void 'reports the generic interfaces declared by the Stampable implementor'() {
            when:
            def interfaces = StampedRecord.genericInterfaces
    
            then:
            interfaces != null
        }
    
        void 'bean introspection of a Stampable implementor succeeds'() {
            when:
            Introspector.getBeanInfo(StampedRecord)
    
            then:
            noExceptionThrown()
        }
    }

    Both fail:

    StampableTraitSpec > reports the generic interfaces declared by the Stampable implementor FAILED
        java.lang.reflect.MalformedParameterizedTypeException at StampableTraitSpec.groovy:11
    
    StampableTraitSpec > bean introspection of a Stampable implementor succeeds FAILED
        Caused by: java.lang.reflect.MalformedParameterizedTypeException at StampableTraitSpec.groovy:20
    
    2 tests completed, 2 failed
    

    with the same message shape as LogicalDelete:

    java.lang.reflect.MalformedParameterizedTypeException: Mismatch of count of formal and actual type arguments
      in constructor of grails.plugins.orm.auditable.Stampable$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.Introspector.getTargetMethodInfo(Introspector.java:1030)
    	at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:446)
    

    And javap on the Grails 8 compiled class shows the invalid signature being emitted, the type argument on a FieldHelper that has none:

    public class stampable.StampedRecord
      implements grails.plugins.orm.auditable.Stampable<stampable.StampedRecord>,
                 grails.plugins.orm.auditable.Stampable$Trait$FieldHelper<stampable.StampedRecord>,
                 org.grails.datastore.mapping.dirty.checking.DirtyCheckable$Trait$FieldHelper,
                 org.grails.datastore.gorm.GormValidateable$Trait$FieldHelper,
                 groovy.lang.GroovyObject
    

    Again note the contrast within one signature: the Grails 8 compiled DirtyCheckable$Trait$FieldHelper and GormValidateable$Trait$FieldHelper appear correctly without type arguments.

    Why this raises the severity

    • It needs no Spring context, no GORM session, and no running application - merely compiling a class against the trait and reflecting over it is enough. Anything doing bean introspection (JavaBeans, Spring, Jackson, many serializers) will hit it.
    • Stampable is applied by application authors to their own domain classes, so the blast radius is the user's code rather than a single plugin internal.
    • It is currently invisible: audit-logging:6.0.0 fails earlier during doWithSpring for the unrelated Holders timing 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.
  3. jamesfredley commented on Oct 2, 2026

    @jamesfredley
    ContributorAuthor

    A Grails 7 plugin that exposes a generic trait with fields still fails on Grails 8 with MalformedParameterizedTypeException mentioning $Trait$FieldHelper. There is no compile-time check that names the plugin and trait, and Groovy was not changed to accept the older FieldHelper bytecode. 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 in v8.0.0-M6, v8.0.0-RC1, and v8.0.0-RC2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions