SimpleStubFactory has to be more precise about supports()

This commit is contained in:
Dave Syer
2025-05-17 08:36:45 +01:00
parent c6f765e507
commit 2edb857dfc
2 changed files with 58 additions and 3 deletions

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.grpc.client;
import java.lang.reflect.Method;
import org.springframework.util.ReflectionUtils;
import io.grpc.stub.AbstractStub;
@@ -23,8 +25,12 @@ public class SimpleStubFactory extends AbstractStubFactory<AbstractStub<?>> {
public static boolean supports(Class<?> type) {
Class<?> factory = type.getEnclosingClass();
return AbstractStubFactory.supports(AbstractStub.class, type) && factory != null
&& ReflectionUtils.findMethod(factory, "newStub", (Class<?>[]) null) != null;
return AbstractStubFactory.supports(AbstractStub.class, type) && factory != null && hasMethod(factory, type);
}
private static boolean hasMethod(Class<?> factory, Class<?> type) {
Method method = ReflectionUtils.findMethod(factory, "newStub", (Class<?>[]) null);
return method != null && method.getReturnType().isAssignableFrom(type);
}
@Override