Skip to content

ClassCastException with generic input class #333

Closed

Description

@fp31

When I write this code:

public class Ab implements GraphQLQueryResolver {
@Data
@NoArgsConstructor
public static class A<T> {
        private T e;
}

public ... find(A<B> c) {
        return ...
}

}

I have the exception below:

Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
at com.coxautodev.graphql.tools.UtilsKt.unwrap(Utils.kt:34)
at com.coxautodev.graphql.tools.GenericType$RelativeTo.parameterizedDeclaringTypeOrSuperType(GenericType.kt:116)
at com.coxautodev.graphql.tools.GenericType$RelativeTo.unwrapGenericType(GenericType.kt:98)
at com.coxautodev.graphql.tools.TypeClassMatcher.match(TypeClassMatcher.kt:34)
at com.coxautodev.graphql.tools.TypeClassMatcher.match(TypeClassMatcher.kt:28)
at com.coxautodev.graphql.tools.SchemaClassScanner.handleNewType(SchemaClassScanner.kt:348)
at com.coxautodev.graphql.tools.SchemaClassScanner.handleFoundType(SchemaClassScanner.kt:328)
at com.coxautodev.graphql.tools.SchemaClassScanner.handleFoundType(SchemaClassScanner.kt:293)
at com.coxautodev.graphql.tools.SchemaClassScanner.scanResolverInfoForPotentialMatches(SchemaClassScanner.kt:268)
at com.coxautodev.graphql.tools.SchemaClassScanner.handleRootType(SchemaClassScanner.kt:119)
at com.coxautodev.graphql.tools.SchemaClassScanner.scanForClasses(SchemaClassScanner.kt:77)
at com.coxautodev.graphql.tools.SchemaParserBuilder.scan(SchemaParserBuilder.kt:165)
at com.coxautodev.graphql.tools.SchemaParserBuilder.build(SchemaParserBuilder.kt:206)
at com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration.schemaParser(GraphQLJavaToolsAutoConfiguration.java:98)
at com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$3d1621d9.CGLIB$schemaParser$0()
at com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$3d1621d9$$FastClassBySpringCGLIB$$a377c22.invoke()

I don't understand why Could you help me ? Thanks

Activity

  1. reopened this on Nov 6, 2019
  2. oryan-block commented on Oct 3, 2026

    @oryan-block
    Collaborator

    Fixed by #819 (same root cause as #468): generic input classes like A<B> now work as resolver arguments. That includes the same generic class used with different type arguments, and generic inputs nested inside other inputs. Covered by GenericInputTypesTest. This ships in 14.0.4.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions