Skip to content

Commit

Permalink
Fix ParameterizedType in SERVER_STREAM (#14763)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbumenJ authored Oct 22, 2024
1 parent 79e6170 commit 542479b
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.dubbo.rpc.model.StubMethodDescriptor;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class MethodMetadata {

Expand Down Expand Up @@ -64,18 +65,18 @@ private static MethodMetadata doResolveReflection(ReflectionMethodDescriptor met
case CLIENT_STREAM:
case BI_STREAM:
actualRequestTypes = new Class<?>[] {
(Class<?>)
((ParameterizedType) method.getMethod().getGenericReturnType()).getActualTypeArguments()[0]
obtainActualTypeInStreamObserver(
((ParameterizedType) method.getMethod().getGenericReturnType()).getActualTypeArguments()[0])
};
actualResponseType =
(Class<?>) ((ParameterizedType) method.getMethod().getGenericParameterTypes()[0])
.getActualTypeArguments()[0];
actualResponseType = obtainActualTypeInStreamObserver(
((ParameterizedType) method.getMethod().getGenericParameterTypes()[0])
.getActualTypeArguments()[0]);
return new MethodMetadata(actualRequestTypes, actualResponseType);
case SERVER_STREAM:
actualRequestTypes = new Class[] {method.getMethod().getParameterTypes()[0]};
actualResponseType =
(Class<?>) ((ParameterizedType) method.getMethod().getGenericParameterTypes()[1])
.getActualTypeArguments()[0];
actualResponseType = obtainActualTypeInStreamObserver(
((ParameterizedType) method.getMethod().getGenericParameterTypes()[1])
.getActualTypeArguments()[0]);
return new MethodMetadata(actualRequestTypes, actualResponseType);
case UNARY:
actualRequestTypes = method.getParameterClasses();
Expand All @@ -84,4 +85,11 @@ private static MethodMetadata doResolveReflection(ReflectionMethodDescriptor met
}
throw new IllegalStateException("Can not reach here");
}

static Class<?> obtainActualTypeInStreamObserver(Type typeInStreamObserver) {
return (Class<?>)
(typeInStreamObserver instanceof ParameterizedType
? ((ParameterizedType) typeInStreamObserver).getRawType()
: typeInStreamObserver);
}
}

0 comments on commit 542479b

Please sign in to comment.