Skip to content

"Class must not be null" error when Consumer uses 2 level generis #1333

@oleksiimiroshnyk

Description

@oleksiimiroshnyk

Describe the bug

I have a consumer bean:

BindingConsumer<Message<String>> consumer(){...}

This is my class that implements Consumer interface:

class BindingConsumer<T> implements Consumer<T>

When I run test it fails with error:

Caused by: java.lang.IllegalArgumentException: Class must not be null
	at org.springframework.util.Assert.notNull(Assert.java:182) ~[spring-core-7.0.3.jar:7.0.3]
	at org.springframework.core.ResolvableType.forClassWithGenerics(ResolvableType.java:1172) ~[spring-core-7.0.3.jar:7.0.3]
	at org.springframework.cloud.function.context.catalog.FunctionTypeUtils.resolveType(FunctionTypeUtils.java:386) ~[spring-cloud-function-context-5.0.1.jar:5.0.1]
	at org.springframework.cloud.function.context.catalog.FunctionTypeUtils.getInputType(FunctionTypeUtils.java:436) ~[spring-cloud-function-context-5.0.1.jar:5.0.1]
	at org.springframework.cloud.function.context.FunctionRegistration.type(FunctionRegistration.java:129) ~[spring-cloud-function-context-5.0.1.jar:5.0.1]
	at org.springframework.cloud.function.context.catalog.BeanFactoryAwareFunctionRegistry.lookup(BeanFactoryAwareFunctionRegistry.java:192) ~[spring-cloud-function-context-5.0.1.jar:5.0.1]

If I change my class signature:

class BindingConsumer<T> implements Consumer<Message<T>>

and create bean:

BindingConsumer<String> consumer(){...}

Everything works fine.

Looks like a bug in
org.springframework.cloud.function.context.catalog.FunctionTypeUtils#resolveType

			return ResolvableType.forClassWithGenerics(typeWithGenerics.getRawClass(),
				resolvedGenerics.toArray(new ResolvableType[0])).getType();

typeWithGenerics.getRawClass() returns null. I think it can be more smart and return Message

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions