Skip to content

Regression in FunctionTypeUtils.discoverFunctionalMethod. Parent class function no longer found #1213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pgehl opened this issue Dec 3, 2024 · 0 comments
Labels
Milestone

Comments

@pgehl
Copy link

pgehl commented Dec 3, 2024

Describe the bug
spring-cloud: 2024.0.0
spring-cloud-function-context: 4.2.0

After udating to spring-cloud version 2024.0.0 our pojo function class extending an abstract class containing void accept(Message message) is no longer found by FunctionTypeUtils.discoverFunctionalMethod.
Instead the application does not start with following exception:

Caused by: java.lang.IllegalArgumentException: Only Supplier, Function or Consumer supported at the moment. Was class com.cie.sample.events.SampleEventConsumer
	at org.springframework.util.Assert.isTrue(Assert.java:116)

Sample
Parent class:

import org.springframework.messaging.Message;
import java.util.function.Consumer;
public abstract class AbstractConsumer<T> implements Consumer<T> {
    @Override
    public final void accept(Message<T> message) {
        if (message == null) {
            return;
        }

        doAccept(message.getPayload());
    }

    protected abstract void doAccept(T payload);
}

Child

public class SampleEventConsumer extends AbstractConsumer<SampleData> {
	@Override
	protected void doAccept(SampleData data) {
	}
}

Trouble shooting
In spring-cloud version 2023.0.4 FunctionTypeUtils checks if class isAssignableFrom supported functions.

public static Method discoverFunctionalMethod(Class<?> pojoFunctionClass) {
	if (Supplier.class.isAssignableFrom(pojoFunctionClass)) {
		return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
				&& m.getName().equals("get")).findFirst().get();
	}
	else if (Consumer.class.isAssignableFrom(pojoFunctionClass) || BiConsumer.class.isAssignableFrom(pojoFunctionClass)) {
		return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
				&& m.getName().equals("accept")).findFirst().get();
	}
	else if (Function.class.isAssignableFrom(pojoFunctionClass) || BiFunction.class.isAssignableFrom(pojoFunctionClass)) {
		return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
				&& m.getName().equals("apply")).findFirst().get();
	}
[...]

Since spring-cloud: 2024.0.0 FunctionTypeUtils only check if the class == pojoFunctionClass

public static Method discoverFunctionalMethod(Class<?> pojoFunctionClass) {
	List<Method> methods = new ArrayList<>();
	ReflectionUtils.doWithMethods(pojoFunctionClass, method -> {
		if (method.getDeclaringClass() == pojoFunctionClass
[...]

The change was made in GH-1204 Remove dependency on Typetools

@olegz olegz added the bug label Dec 9, 2024
@olegz olegz added this to the 4.2.1 milestone Dec 9, 2024
@olegz olegz closed this as completed in 622cbda Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants